Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdlib.h>
- struct node
- {
- int a;
- struct node*p;
- };
- void Insertion_last_Position(struct node *head,int value);
- void Display (struct node *head);
- int count(struct node *head);
- int main()
- {
- int n,i,c,pos,v,q;
- struct node *list;
- list =(struct node*)malloc(1* sizeof(struct node));
- list->a=0;
- list->p=NULL;
- while (1)
- {
- printf("\n--------Menu---------");
- printf("\n Press 0 for Quit");
- printf("\n press 1 for Insertion At Last Position");
- printf("\n press 2 for Insertion Specific Position");
- printf("\n press 3 for Display");
- printf ("\n press 4 for Deletion from specific Position");
- printf ("\n press 5 for Count Total Node");
- printf ("\n press 6 for Linear Search");
- printf ("\n Enter Your choice\n");
- scanf("%d",&c);
- switch(c)
- {
- case 0: exit(0);
- break;
- case 1: printf ("\n choice= Insertion at Last Position");
- printf("\n Enter New Value\n");
- scanf("%d",&v);
- Insertion_last_Position(list,v);
- break;
- case 3: printf("\n choice=Display\n");
- if
- (list->p!=NULL)
- Display (list);
- else
- printf("\n The list is Empty\n");
- break;
- case 5: printf ("\n choice=Counting Total Node\n");
- n= count(list);
- printf("\n Total Node=%d\n",n);
- break;
- }
- }
- }
- void Insertion_last_Position(struct node *head,int value)
- {
- struct node *temp;
- while(head->p!=NULL)
- head=head->p;
- temp=(struct node*)malloc(1*sizeof(struct node));
- temp->a=value;
- temp->p=NULL;
- head->p=temp;
- }
- void Display (struct node *head)
- {
- while(head->p!=NULL)
- {
- printf("%d\n",head->p->a);
- head=head->p;
- }
- }
- int count(struct node *head)
- {
- int t=0;
- while(head->p!=NULL)
- {
- t=t+1;
- head=head->p;
- }
- return t;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement