Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct stack{
- int x;
- struct stack *next;
- }*top=NULL;
- void push(int n){
- struct stack *temp;
- temp=(struct stack*)malloc(sizeof(struct stack));
- temp->x=n;
- if(top==NULL)
- {
- temp->next=NULL;
- top=temp;
- }
- else{
- temp->next=top;
- top=temp;
- }
- }
- void pop()
- {
- if(top==NULL)
- {
- printf("The stack is underflow!!\n");
- }
- else{
- top=top->next;
- }
- }
- void display()
- {
- struct stack *c=top;
- while(c!=NULL)
- {
- printf("%d\n",c->x);
- c=c->next;
- }
- printf("\n");
- }
- int main()
- {
- push(11);
- display();
- push(7);
- display();
- push(5);
- display();
- pop();
- display();
- push(12);
- push(9);
- display();
- pop();
- display();
- pop();
- display();
- pop();
- display();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement