Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- struct node
- {
- int data;
- struct node * link;
- };
- void Push(int vv);
- void Pop ();
- void Display();
- void Count();
- struct node* top= NULL,*temp;
- int main()
- {
- int c,v;
- while(1)
- {
- printf("\-------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 Quit\n");
- printf("\n enter your choice\n");
- scanf("%d",&c);
- switch(c)
- {
- case 1:printf("\n choice = Push\n");
- printf("\n Enter value for insertion \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 the stack is empty\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\n",temp->data);
- temp=temp->link;
- }
- }
- void Pop ()
- {
- temp=top;
- top=temp->link;
- printf("\n the deleted node= %d\n",temp->data);
- free(temp);
- }
- void Count()
- {
- int n=0;
- temp=top;
- while(temp!=NULL)
- {
- n=n+1;
- temp=temp->link;
- }
- printf("\n total value=%d\n",n);
- }
Advertisement
Add Comment
Please, Sign In to add comment