Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node
- {
- int data;
- struct node *link;
- };
- struct node *top=NULL;
- void push(int x)
- {
- struct node *N = new node;
- N->data=x;
- N->link=NULL;
- if(top==NULL)
- {
- top=N;
- }
- else
- {
- N->link=top;
- top=N;
- }
- }
- void pop()
- {
- if(top==NULL)
- {
- cout<<"There's no values in the list"<<endl;
- }
- else
- {
- top=top->link;
- }
- }
- void display()
- {
- struct node *t =top;
- while(t->link!=NULL)
- {
- cout<<t->data<<"->";
- t=t->link;
- }
- cout<<t->data<<endl;
- }
- int main()
- {
- push(10);
- push(20);
- push(30);
- display();
- pop();
- display();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement