Question: Exercise A ( in c++ ) Use a linked list to implement a stack. The stack should store characters. The stack should support the following

Exercise A

(in c++) Use a linked list to implement a stack. The stack should store characters. The stack should support the following operations/functions:-

1. push:- adds a new element to the top of the stack. Push should take a character as an argument (the character to be pushed onto the stack).

2. pop:- removes an element from the top of the stack. Pop should return a character. (the character popped off the stack. If the stack is empty when pop is called it should return the null character.).

3. empty:- returns a true or false value depending on whether the stack is empty of not.

To test the stack code push the following characters onto the stack t, e, s, t, a, n, g. Pop three characters off the stack. Then push the characters i, n, g onto the stack. Finally pop all of the remaining characters off the stack and print them in the order they are popped. You should use a loop, using the empty operation as part of the stopping condition, to pop and print the stack.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!