TAEEEEE123
Established
#include <iostream>
using namespace std;
struct Node{
int data;
Node *link;
};
Node *top = NULL;
bool isempty(){
if(top == NULL)
return true;
else
return false;
}
void push (int value){
Node *ptr = new Node();
ptr->data = value;
ptr->link = top;
top = ptr;
}
void pop ( ){
if ( isempty() )
cout<<"Stack is Empty";
else{
cout<<("\n");
cout<<top->data <<(" is popped\n");
Node *ptr = top;
top = top -> link;
delete(ptr);
}
}
void displayStack(){
if ( isempty() )
cout<<"Stack is Empty";
else{
Node *temp=top;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->link;
}
cout<<"\n";
}
}
int main(){
int choice, flag=1, value;
cout<<("\n======= Menu =======")<<endl
<<("\n1. Push data") <<endl
<<("2. Pop data") <<endl
<<("3. Display")<<endl
<<("4. Undo")<<endl
<<("5. Delete")<<endl
<<("6. Exit\n");
while( flag == 1){
cout<<("\nEnter choice: ");
cin>>choice;
switch (choice){
case 1: cout<<"Enter Value: ";
cin>>value;
push(value);
break;
case 2: pop();
break;
case 3: displayStack();
break;
case 4:
case 5:
case 6: flag = 0;
break;
}
}
return 0;
}
Anong Logic Coding and gagawin ko para malagayan ng undo saka delete and stack using linked list ko an program??
using namespace std;
struct Node{
int data;
Node *link;
};
Node *top = NULL;
bool isempty(){
if(top == NULL)
return true;
else
return false;
}
void push (int value){
Node *ptr = new Node();
ptr->data = value;
ptr->link = top;
top = ptr;
}
void pop ( ){
if ( isempty() )
cout<<"Stack is Empty";
else{
cout<<("\n");
cout<<top->data <<(" is popped\n");
Node *ptr = top;
top = top -> link;
delete(ptr);
}
}
void displayStack(){
if ( isempty() )
cout<<"Stack is Empty";
else{
Node *temp=top;
while(temp!=NULL){
cout<<temp->data<<" ";
temp=temp->link;
}
cout<<"\n";
}
}
int main(){
int choice, flag=1, value;
cout<<("\n======= Menu =======")<<endl
<<("\n1. Push data") <<endl
<<("2. Pop data") <<endl
<<("3. Display")<<endl
<<("4. Undo")<<endl
<<("5. Delete")<<endl
<<("6. Exit\n");
while( flag == 1){
cout<<("\nEnter choice: ");
cin>>choice;
switch (choice){
case 1: cout<<"Enter Value: ";
cin>>value;
push(value);
break;
case 2: pop();
break;
case 3: displayStack();
break;
case 4:
case 5:
case 6: flag = 0;
break;
}
}
return 0;
}
Anong Logic Coding and gagawin ko para malagayan ng undo saka delete and stack using linked list ko an program??