Advertisement
Guest User

Insert_in_the_beginning_of_the_list

a guest
Feb 21st, 2019
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.79 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. typedef struct my
  5. {
  6.     int value;
  7.     struct my *after;
  8. }my;
  9. my *head = NULL;
  10. int main()
  11. {
  12.     int i,n,m;
  13.     my *coming;
  14.     printf("Inpute the number of nodes: ");
  15.     scanf("%d",&n);
  16.     for(i=1;i<=n;i++)
  17.     {
  18.         printf("Inpute data for node %d : ",i);
  19.         scanf("%d",&m);
  20.         coming = malloc(sizeof(my));
  21.         coming->value = m;
  22.         if(head == NULL)
  23.         {
  24.         head = coming;
  25.         head -> after = NULL;
  26.         }
  27.         else
  28.         {
  29.           coming -> after = head;
  30.           head = coming;
  31.         }
  32.     }
  33.     coming=head;
  34.     printf("Data entered in the list :\n");
  35.     while(coming!=NULL)
  36.     {
  37.     printf(" Data=%d\n",coming->value);
  38.     coming=coming->after;
  39.     }
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement