Question: #include using namespace std; struct Node { int data; struct Node * next; } ; Node * push ( Node * top , int data
#include
using namespace std;
struct Node
int data;
struct Node next;
;
Node pushNode top int data
Node newNode new Node;
newNodedata data;
newNodenext NULL;
if top NULL
top newNode;
else
newNodenext top;
top newNode;
return top;
int topNode top return topdata;
int popNode top
if top NULL
Node temp top;
int x topdata; or int x temp data;
top topnext;
delete temp;
return x;
else
return ;
void printStackNode top
iftop NULL
Node cur top;
while cur NULL
cout curdata ;
cur curnext;
cout endl;
Node valueCheckNode stackTop
return stackTop;
int main
struct Node myStackTop NULL;
myStackTop pushmyStackTop;
myStackTop pushmyStackTop;
myStackTop pushmyStackTop;
myStackTop pushmyStackTop;
myStackTop pushmyStackTop;
printStackmyStackTop;
myStackTop valueCheckmyStackTop;
printStackmyStackTop;
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
