Advertisement
dllbridge

Untitled

May 4th, 2021
769
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.47 KB | None | 0 0
  1.  
  2.  
  3. #include  <stdio.h>
  4. #include <stdlib.h>
  5.  
  6.  
  7. int num_of_nodes = 121;
  8.  
  9.  
  10. void  init_linked_list(struct ListNode  *list);
  11. void print_linked_list(struct ListNode  *list);    
  12.  
  13. struct ListNode
  14. {
  15.    
  16.        int value;
  17.        struct ListNode* next;
  18.        
  19. }*list;
  20.  
  21. ///////////////////////////////////////////////////////////////////////////////  
  22. int main()                                                                   //
  23. {
  24.    
  25.     srand(7);
  26.    
  27.     list = 0;
  28.     //init_linked_list(&list);
  29.      init_linked_list(list);
  30.     print_linked_list(list);
  31.  
  32. return 0;
  33. }
  34.  
  35.  
  36.  
  37.  
  38. ///////////////////////////////////////////////////////////////////////////////
  39. //void init_linked_list(struct ListNode** list)                              //
  40. void init_linked_list(struct ListNode* list)                                 //
  41. {
  42.    
  43.      //struct ListNode *cur = *list;
  44.      struct ListNode *cur = list;
  45.        
  46.      for(int i = 0; i < num_of_nodes; i++)
  47.      {
  48.        
  49.        //cur =                   malloc(sizeof(struct ListNode));  
  50.          cur = (struct ListNode*)malloc(sizeof(struct ListNode));
  51.          cur->value = rand();
  52.          cur = cur->next;
  53.      }
  54. }
  55.  
  56. ///////////////////////////////////////////////////////////////////////////////  
  57. void print_linked_list(struct ListNode *list)                                //
  58. {
  59.  
  60.      struct ListNode *cur = list;
  61.      
  62.      while(cur)
  63.      {
  64.          printf("%d\n", cur->value);
  65.          cur = cur->next;
  66.      }
  67. }
  68.  
  69.  
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement