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 *push(Node *top, int data){
Node *newNode = new Node;
newNode->data = data;
newNode->next = NULL;
if (top == NULL){
top = newNode;
} else {
newNode->next = top;
top = newNode;
}
return top;
}
int top(Node *top){ return top->data; }
int pop(Node **top){
if (*top != NULL){
Node *temp =*top;
int x =(*top)->data; // or int x = temp -> data;
*top =(*top)->next;
delete temp;
return x;
} else
return -1;
}
void printStack(Node *top){
if(top != NULL){
Node *cur = top;
while (cur != NULL){
cout cur->data "";
cur = cur->next;
}
cout endl;
}
}
Node *valueCheck(Node *stackTop){
return stackTop;
}
int main(){
struct Node *myStackTop = NULL;
myStackTop = push(myStackTop,2);
myStackTop = push(myStackTop,5);
myStackTop = push(myStackTop,18);
myStackTop = push(myStackTop,15);
myStackTop = push(myStackTop,7);
printStack(myStackTop);
myStackTop = valueCheck(myStackTop);
printStack(myStackTop);
return 0;
}
 #include using namespace std; struct Node { int data; struct Node

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!