Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //D.B.John PC
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- struct node *link;
- };
- struct node *top=NULL,*temp;
- void push(int vv);
- void Display();
- void Delete();
- void Count();
- // int count(struct node *head);
- // void Insertion_last_position(struct node *head, int value);
- // void Insertion_specific_position(struct node *head, int vv, int pp);
- // void Deletion_specific_position(struct node *head, int pp);
- int main()
- {
- int c,v;
- while(1)
- {
- printf("\n ....Menu....\n");
- printf("\n press 1 for Push \n");
- printf("\n press 2 Poop \n");
- printf("\n press 3 Display\n");
- printf("\n press 4 Count\n");
- printf("\n press 5 Quit\n");
- printf("\n Enter your choise \n");
- scanf("%d",&c);
- switch(c)
- {
- case 5:exit (0);
- break;
- case 1:printf("\n choise=Push \n ");
- printf("\n Enter NEW value\n");
- scanf("%d",&v);
- push(v);
- break;
- case 3: printf("\n Choise=Display \n");
- if(top!=NULL)
- Display();
- else
- printf("\n NO data to display \n");
- break;
- case 2: printf("\n choise=pop\n");
- if(top!=NULL)
- Delete();
- else
- printf("\n NO data to delet\n");
- break;
- case 4: printf("\n choise=count\n");
- Count();
- break;
- default:printf("\n Wrong Choise\n");
- 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 Delete()
- {
- temp=top;
- top=temp->link;
- printf("\n The delete value =%d", temp->data);
- free(temp);
- }
- void Count()
- {
- int i=0;
- temp=top;
- while(temp!=NULL)
- {
- i=i+1;
- temp=temp->link;
- }
- printf("\n Total node=%d\n",i);
- }
Add Comment
Please, Sign In to add comment