Question: Write a C++ linked list based stack program that will read the command and push the value in the input.txt into stack and pop it

Write a C++ linked list based stack program that will read the command and push the value in the input.txt into stack and pop it into another output.txt. With the struct below:

typedef struct Node

{

int val;

Node *next;

} Node;

class Stack

{

private:

Node *head;

unsigned int s_size;

public:

Stack();

void push(int a);

int pop();

};

Input.txt example 1:

c (create an empty stack) push 2 push 4 push 6 pop pop pop

Expected output.txt 1:

6

4

2

input.txt example 2:

c (create an empty stack) push 1 pop pop

Expected output.txt 2:

1

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!