Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int num_of_nodes = 121;
- void init_linked_list(struct ListNode *list);
- void print_linked_list(struct ListNode *list);
- struct ListNode
- {
- int value;
- struct ListNode* next;
- }*list;
- ///////////////////////////////////////////////////////////////////////////////
- int main() //
- {
- srand(7);
- list = 0;
- //init_linked_list(&list);
- init_linked_list(list);
- print_linked_list(list);
- return 0;
- }
- ///////////////////////////////////////////////////////////////////////////////
- //void init_linked_list(struct ListNode** list) //
- void init_linked_list(struct ListNode* list) //
- {
- //struct ListNode *cur = *list;
- struct ListNode *cur = list;
- for(int i = 0; i < num_of_nodes; i++)
- {
- //cur = malloc(sizeof(struct ListNode));
- cur = (struct ListNode*)malloc(sizeof(struct ListNode));
- cur->value = rand();
- cur = cur->next;
- }
- }
- ///////////////////////////////////////////////////////////////////////////////
- void print_linked_list(struct ListNode *list) //
- {
- struct ListNode *cur = list;
- while(cur)
- {
- printf("%d\n", cur->value);
- cur = cur->next;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement