Question: Write the C + + implementation of the pop member function of the Stack class: pop ( ) : deletes the value at the top
Write the C implementation of the pop member function of the Stack class:
pop: deletes the value at the top of the stack and returns it Assume the stack is not empty no need to check
The push function is given.
Write code in main to test this function. Write a loop to enter an unknown number of strings, one string per line. The loop stops when you enter As you are entering strings, they are to be pushed onto a stack. Once done, pop them out of the stack and display them one per line.
Ex: If the user enters
one
two
three
the output should be:
three
two
one
Ex: If the user enters the output should be:
Empty stack!
~~~
CIS C
Project: Stack of strings pop
Written by:
IDE:
~
#include
#include
using namespace std;
class Stackstr
private:
Structure for the stack nodes
struct StackNode
string value; Value in the node
StackNode next; Pointer to next node
;
StackNode top; Pointer to the stack top
int length;
public:
Stackstr top NULL; length ; Constructor
~Stackstr; Destructor
Stack operations
bool isEmpty; Write your code here
bool pushstring;
string pop;
string peek;
int getLength;
;
~~~
Member function push: pushes the argument onto the stack.
~
bool Stackstr::pushstring item
StackNode newNode; Pointer to a new node
Allocate a new node and store num there.
newNode new StackNode;
if newNode
return false;
newNodevalue item;
Update links and counter
newNodenext top;
top newNode;
length;
return true;
~~~
Member function pop pops the value at the top
of the stack off, and returns it
Assume stack is not empty
~
Define the pop function
int main
Stackstr s;
string item;
Write your code here to test the push and pop functions
return ;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
