Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int a;
- struct node *p;
- };
- int count(struct node *head);
- void Display(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);
- void Linear_search(struct node*head,int vv);
- 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....!!!\n");
- printf("\n press 1 for Insertion \n");
- printf("\n press 2 for Insertion specific position \n");
- printf("\n press 3 Display\n");
- printf("\n press 4 Deletion Spacific positin\n");
- printf("\n press 5 Count Total node\n");
- printf("\n press 6 Linear Search \n");
- printf("\n Enter your choise \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 2: printf("\n choice=Insertion at Specific position\n");
- n=count(list);
- if(n!=0)
- {
- K:printf("\n Enter Position between %d to %d\n",1,n+1);
- scanf("%d",&pos);
- if (pos>=1 && pos<=n+1)
- {
- printf("\n Enter New Value\n");
- scanf("%d",&v);
- Insertion_specific_position(list,v,pos);
- }
- else
- printf("\n Wrong Position\n\n");
- break;
- }
- case 3: printf("\n choice=Display\n");
- if(list->p!=NULL)
- Display(list);
- else
- printf("\n list is Empty \n");
- break;
- case 4: printf("\n choice=Deletion from specific position\n");
- n=count(list);
- if(n!=0)
- {
- L: printf ("\n Enter Position Between %d to %d\n",1,n);
- scanf("%d", & pos);
- if (pos>=1 && pos<=n)
- Deletion_specific_position (list,pos);
- else
- {
- printf("\n Wrong position\n\n");
- goto L;
- }
- break;
- }
- else printf("\n No Data to Delete \n\n");
- break;
- case 5: printf("\n choice=Counting Total node\n");
- n=count(list);
- printf("\n Total Node=%d\n",n);
- break;
- case 6: printf ("\n choice= Linear Search\n");
- n= count(list);
- if(n!=0)
- {
- printf("\n Enter value for Searching\n");
- scanf("%d", & v);
- Linear_search(list,v);
- }
- else
- printf("\n is No Data For Searching\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("\n%d \t",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;
- }
- void Insertion_specific_position(struct node*head,int vv, int pp)
- {
- struct node*temp;
- int i=0;
- while(head->p!=NULL)
- {
- if(i==pp-1)
- break;
- head=head->p;
- i=i+1;
- }
- temp=(struct node*)malloc(1*sizeof(struct node));
- temp ->a=vv;
- temp ->p=head ->p;
- head ->p=temp;
- }
- void Deletion_specific_position(struct node*head, int pp)
- {
- struct node*temp;
- int i=0;
- while(head->p!=NULL)
- {
- if(i==pp-1)
- break;
- head=head->p;
- i=i+1;
- }
- temp=head ->p;
- head ->p=temp ->p;
- free (temp);
- }
- void Linear_search(struct node*head,int vv)
- {
- int c=0, i=0;
- while(head ->p!=NULL)
- {
- if (head ->p->a==vv)
- {
- printf("\n Found At Position =%d",i+1);
- c=1;
- }
- i=i+1;
- head= head ->p;
- }
- if (c ==0)
- printf("\n\n Not Found \n\n");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement