Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<malloc.h>
- struct node
- {
- int data;
- struct node *next;
- };
- struct node *push(struct node *head,int data)
- {
- struct node *nw=NULL;
- nw=(struct node *)malloc(sizeof(struct node));
- nw->data=data;
- nw->next=NULL;
- if(head==NULL)
- {
- head=nw;
- }
- else
- {
- nw->next=head;
- head=nw;
- }
- return(head);
- }
- struct node *pop(struct node *head)
- {
- struct node *cur;
- if(head==NULL)
- printf("Empty\n");
- else
- {
- cur=head;
- printf("%d deleted\n",cur->data);
- head=head->next;
- free(cur);
- }
- return head;
- }
- void main()
- {
- int ch,n;
- struct node *head=NULL;
- do
- {
- printf("1 to push \n2 to pop\n");
- scanf("%d",&ch);
- switch(ch)
- {
- case 1 : printf("Enter data\n");
- scanf("%d",&n);
- head=push(head,n);
- break;
- case 2 : head=pop(head);
- break;
- case 3 : break;
- }
- }while(ch!=3);
- }
Add Comment
Please, Sign In to add comment