Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

// Stack Exercise : Complete the tasks given . The correct // implementation should be as the comments part at the bottom // of this

// Stack Exercise : Complete the tasks given . The correct // implementation should be as the comments part at the bottom // of this file.

// This exercise is for linked List Implementation of Stack

#include using namespace std; class Node { public : string name; int salary; Node *next;

Node() { name = " "; salary = 0; } }; //Node

class Stack { Node *top; public: Stack(); ~Stack(); void push(); void *pop(); void print(); }; //Stack

Stack::Stack() { top = NULL; }

Stack::~Stack() { while(top) { Node *s = top->next; delete top; top = s; } }

void Stack::push() { Node *newnode=new Node(); //Task 1 : Enter name and salary

//Task 2 : Insert newnode as the top/front element }

void *Stack::pop() { Node *t=top; if(top==NULL) cout<<"Stack Underflow"<

void Stack::print() { Node *temp= top; // Task 5 : Display all elements in the stack } cout << endl; }

int main() { Stack *st = new Stack; //Task 6 : Call push method 3 times

st->print(); //Task 7 : Call pop method 2 times

cout << "After poped "; st->print(); cout << endl; return 0; }

// Program implementation //push ### /* Enter name : Sarah Enter salary : 4500 Enter name : Hadi Enter salary : 7800 Enter name : Fang Enter salary : 6500 //display### Fang 6500 Hadi 7800 Sarah 4500 //pop The popped element is Fang 6500 The popped element is Hadi 7800 After poped Sarah 4500 */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Optimization And Data Science Trends And Applications 5th Airoyoung Workshop And Airo Phd School 2021 Joint Event

Authors: Adriano Masone ,Veronica Dal Sasso ,Valentina Morandi

1st Edition

3030862887, 978-3030862886

More Books

Students also viewed these Databases questions

Question

2. Why does unpredictability matter?

Answered: 1 week ago

Question

What were your most important educational experiences?

Answered: 1 week ago

Question

Which personal relationships influenced you the most?

Answered: 1 week ago