Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct Data
- {
- int a;
- struct Data *next,*prev;
- }Data;
- Data *head=NULL;
- void push(int x)
- {
- Data *new_node=(Data*)malloc(sizeof(Data));
- new_node->a=x;
- new_node->next=NULL;
- if(head==NULL)
- {
- head=new_node;
- printf("Push Value %d\n",head->a);
- return;
- }
- new_node->next=head;
- head=new_node;
- printf("Push Value %d\n",head->a);
- }
- int pop()
- {
- Data *dlt=head;
- int x;
- if(head==NULL)
- {
- printf("Empty Stack!\n");
- return -1;
- }
- if(head->next==NULL)
- {
- head=NULL;
- x = dlt -> a;
- free(dlt);
- return x;
- }
- head=head->next;
- x = dlt -> a;
- free(dlt);
- return x;
- }
- void top()
- {
- int x;
- if(head==NULL)
- {
- printf("Noting in Top!\n");
- return;
- }
- x=head->a;
- printf("Top Value: %d\n", x);
- }
- int main()
- {
- pop();
- top();
- push(5);
- pop();
- top();
- push(7);
- push(6);
- push(5);
- top();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement