Advertisement
hasancse1991

linked-list

Dec 3rd, 2018
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.83 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #define NULL 0
  4.  
  5. struct linked_list
  6. {
  7.     int number;
  8.     struct linked_list *next;
  9. };
  10.  
  11. typedef struct linked_list node;
  12.  
  13. void create(node *myList);
  14. void print(node *myList);
  15.  
  16. int main()
  17. {
  18.  
  19.     node *head;
  20.     head = (node *) malloc(sizeof(node));
  21.  
  22.     create(head);
  23.  
  24.     printf("\n");
  25.     print(head);
  26.     printf("\n");
  27.  
  28.  
  29.     return 0;
  30. }
  31.  
  32. void create(node *myList)
  33. {
  34.     printf("Input a number. (Enter -99999 at end)\n");
  35.  
  36.     scanf("%d", &myList->number);
  37.  
  38.     if(myList->number==-99999)
  39.         myList->next = NULL;
  40.     else
  41.     {
  42.         myList->next = (node *) malloc(sizeof(node));
  43.         create(myList->next);
  44.     }
  45. }
  46.  
  47. void print(node *myList)
  48. {
  49.     printf("%d ", myList->number);
  50.  
  51.     if(myList->next == NULL)
  52.         return;
  53.  
  54.     print(myList->next);
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement