added notes

master
nkls 3 months ago
parent 69bc9dcb5d
commit c54060a742

@ -1,3 +1,42 @@
1 everse a linked list by Iterative Method:
2
3 Follow the steps below to solve the problem:
4
5 Initialize three pointers prev as NULL, curr as head, and next as NULL.
6 Iterate through the linked list. In a loop, do the following:
7 Before changing the next of curr, store the next node 
8 next = curr -> next
9 Now update the next pointer of curr to the prev 
10 curr -> next = prev 
11 Update prev as curr and curr as next 
12 prev = curr 
13 curr = next
14
15 /* Function to reverse the linked list */
16 static void reverse(struct Node** head_ref)
17 {
18     struct Node* prev = NULL;
19     struct Node* current = *head_ref;
20     struct Node* next = NULL;
21     while (current != NULL) {
22         // Store next
23         next = current->next;
24  
25         // Reverse current node's pointer
26         current->next = prev;
27  
28         // Move pointers one position ahead.
29         prev = current;
30         current = next;
31     }
32     *head_ref = prev;
33
======================================================================
12:49 <heck> i just made a GNU Make infra for a project yesterday, if you want to check it out
12:50 <heck> its a live-coding lang, and its just a couple of {.c|.h} files linking to 2 external libs, -lportmidi and cant remember... it
genereated 2 different exe's from the source so that clutters the makefile a bit

Binary file not shown.
Loading…
Cancel
Save