Advertisement
shohan11421

QUIZ SOLUTION

Mar 3rd, 2018
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.78 KB | None | 0 0
  1. QUIZ SOLUTION
  2.  
  3. 2)
  4.  
  5. void insert_any(int a, int pos)
  6. {
  7.     struct node *n;
  8.     n = (struct node *) malloc(sizeof(struct node));
  9.     n -> data = a;
  10.     temp = head;
  11.     int i;
  12.     for(i = 0; i < pos - 2; i++)
  13.     {
  14.         temp = temp -> next;
  15.     }
  16.     n -> next = temp -> next;
  17.     temp -> next = n;
  18. }
  19.  
  20.  
  21. 3)
  22.  
  23. void del_any_pos(int a)
  24. {
  25.  
  26.     struct node *temp2;
  27.     temp = head;
  28.     while(temp ->data != a)
  29.     {
  30.         temp2 = temp;
  31.         temp = temp -> next;
  32.     }
  33.     temp2 -> next = temp -> next;
  34.     free(temp);
  35. }
  36.  
  37.  
  38. 4)
  39.  
  40. void search(int a)
  41. {
  42.     temp = head;
  43.     int flag = 0;
  44.     while(temp)
  45.     {
  46.         if(temp -> data == a) flag = 1;
  47.         temp = temp -> next;
  48.     }
  49.     if(flag == 1) printf("Found\n");
  50.     else printf("Not Found\n");
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement