Advertisement
ahamed210

insert_header_file

Oct 5th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.73 KB | None | 0 0
  1. void add_node(Node *head)
  2. {
  3.     int position, count=0, i=1;
  4.     printf("enter the position after that place new node will be inserted : ");
  5.     scanf("%d", &position);
  6.     Node *temp;
  7.     temp = head;
  8.     while(temp != NULL)
  9.     {
  10.         count++;
  11.         temp = temp->next;
  12.     }
  13.     if(position>count){
  14.         printf("Invalid selection!!!\n");
  15.     }
  16.     else
  17.     {
  18.         temp = head;
  19.         while(i<position)
  20.         {
  21.             temp = temp->next;
  22.             i++;
  23.         }
  24.         Node *new_node = (Node *)malloc(sizeof(Node));
  25.         printf("\nEnter Node item for the perticular position : ");
  26.         scanf("%d", &new_node->data);
  27.         new_node->next = temp->next;
  28.         temp->next=new_node;
  29.     }
  30. }
  31.  
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement