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(struct node *head, int value);
- void Display(struct node *head);
- int main()
- {
- int n,i,c,v,p,q;
- struct node *list;
- list=(struct node *) malloc(1*sizeof(struct node));
- list->a=0;
- list->p=NULL;
- printf("\n----------Menu-----------\n");
- printf("\nPress 0 for quit\n");
- printf("\nPress 1 for insertion at last position\n");
- printf("\nPress 2 for insertion at specific position\n");
- printf("\nPress 3 for display\n");
- printf("\nPress 4 for deletion at specific position\n");
- printf("\nPress 5 for counting total node\n");
- printf("\nPress 2 for linear search\n");
- printf("\nEnter your choice:\n");
- scanf("%d",&c);while(1)
- {
- switch(c)
- {
- case 0: exit(0);
- break;
- case 1: printf("\nchoice = Insertion at last position\n");
- printf("\n Enter new value \n");
- scanf("%d",&v);
- Insertion_Last(list,v);
- break;
- case 3: printf("\nchoice = Display\n");
- if(list->p!=NULL)
- Display(list);
- else
- printf("\nThe list is empty\n");
- break;
- default: printf("\n\n Wrong position\n");
- }
- }
- }
- void Insertion_Last(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("\t->%d->",head->p->a);
- head=head->p;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment