❓ Help Dev C++

Status
Not open for further replies.

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??
 
Status
Not open for further replies.

About this Thread

  • 0
    Replies
  • 271
    Views
  • 1
    Participants
Last reply from:
TAEEEEE123

Trending Topics

Online now

Members online
1,707
Guests online
1,126
Total visitors
2,833

Forum statistics

Threads
2,272,607
Posts
28,943,898
Members
1,237,265
Latest member
Wesleymenger
Back
Top