SAADQUAMER

Untitled

Oct 11th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.38 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3.  
  4. typedef struct node
  5. {
  6.     int a;
  7.     char ch;
  8.     struct node *next;
  9.  
  10. } node;
  11.  
  12. node *head;
  13.  
  14.  
  15.  
  16. void display()
  17. {
  18.  
  19.     node *list=head;
  20.     while(list !=NULL)
  21.     {
  22.         printf("\n\nA= %d ,C= %c\n",list->a,list->ch);
  23.  
  24.  
  25.         list=list->next;
  26.  
  27.     }
  28. }
  29.  
  30. void insert_end(int aN,char chN)
  31. {
  32.     node *N=(node*)malloc(sizeof(node));
  33.     N->a=aN;
  34.     N->ch=chN;
  35.     N->next=NULL;
  36.     node *list=head;
  37.     if(head==NULL)
  38.     {
  39.         head=N;
  40.         list=N;
  41.     }
  42.     else
  43.     {
  44.         while(list->next!=NULL)
  45.         {
  46.             list=list->next;
  47.         }
  48.         list->next=N;
  49.  
  50.     }
  51.  
  52. }
  53. void delete_item(int value)
  54. {
  55.     node *list = head, *temp=NULL;
  56.     int x = 0;
  57.  
  58.     while(list!=NULL)
  59.     {
  60.         if(list->a==value)
  61.         {
  62.             if(temp==NULL)
  63.                 head = list->next;
  64.             else
  65.                 temp->next = list->next;
  66.  
  67.             printf("%d is deleted from list\n", value);
  68.             x = 1;
  69.             free(list);
  70.             break;
  71.         }
  72.         temp = list;
  73.         list = list->next;
  74.     }
  75.     if(x==0)
  76.         printf("Key not found!\n");
  77. }
  78.  
  79. int main()
  80. {int value;
  81.     head=NULL;
  82.     insert_end(5,'p');
  83.     insert_end(4,'r');
  84.     insert_end(2,'u');
  85. printf("ENTER Value FOR DELETE:");
  86. scanf("%d",&value);
  87. delete_item(value);
  88.     display();
  89.  
  90. }
Advertisement
Add Comment
Please, Sign In to add comment