Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- struct node *link;
- };
- struct node *top=NULL,*temp;
- void Display();
- void push(int vv);
- void pop();
- void count();
- int main()
- {
- int c,v;
- while(1)
- {
- printf("\n -----Menu-----\n");
- printf("\n press 1 for Push\n");
- printf("\n press 2 for pop\n");
- printf("\n press 3 for Display\n");
- printf("\n press 4 for count\n");
- printf ("\n press 5 for Exit\n");
- printf ("\n Enter Your Choice\n");
- scanf("%d",&c);
- switch(c)
- {
- case 1:printf ("\n choice=push\n");
- printf("\n Enter New Vlue\n");
- scanf("%d",&v);
- push (v);
- break;
- case 2: printf("\n choice=pop\n");
- if (top!=NULL)
- pop();
- else
- printf("\n No Data To Delete\n");
- break;
- case 3: printf("\n choice=Display\n");
- if (top!=NULL)
- Display();
- else
- printf("\n No Data to Display\n");
- break;
- default: printf("\n Wrong choice\n\n");
- break;
- case 4:printf ("\n choice=Count\n");
- count();
- break;
- case 5: exit(0);
- break;
- }
- }
- }
- void push(int vv)
- {
- temp=(struct node*)malloc(1*sizeof(struct node));
- temp->data=vv;
- temp->link=top;
- top= temp;
- }
- void Display()
- {
- temp=top;
- while(temp!=NULL)
- {
- printf("\n %d", temp->data);
- temp=temp->link;
- }
- }
- void count()
- {
- int i=0;
- temp=top;
- while(temp!=NULL)
- {
- i=i+1;
- temp=temp->link;
- }
- printf("\n Total node=%d\n",i);
- }
- void pop()
- {
- temp=top;
- top=temp->link;
- printf("\n The Deleted value=%d\n",temp->data);
- free(temp);
- }
Add Comment
Please, Sign In to add comment