Skip to content

Commit 555ada2

Browse files
committed
minor additions
1 parent bce9e2a commit 555ada2

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ only if there is one number that repeats odd number of times
2222
which has to be returned
2323
- Sometimes if the algo seems to be complicated move to a generalized format where the result is assumed to be N and you are solving it for some x by going from solution to problem, and then try to figure out the algo. (refer question 28.c for more clarification)
2424

25+
### For Linked Lists: (methods that can be applied)
26+
- Use multiple variables to not loose track of the linked list and keep moving them ahead in a manner such that various operations can be done on a linked list
27+
- If you dont want a function to return a value of something, just send that value to the address of the variable by passing the address of variable as argument and accessing it has **
28+
29+
2530
# General hash functions
2631
- take mod with number of elements present
2732

linked-lists/question4.c

+17-14
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,22 @@ struct node{
99
struct node *link;
1010
};
1111

12+
void reverse(struct node **head){
13+
//reversing the list
14+
struct node *curr, *prev,*nextNode;
15+
curr = *head;
16+
17+
prev = NULL;
18+
while(curr){
19+
nextNode = curr->link;
20+
curr->link = prev;
21+
prev = curr;
22+
curr = nextNode;
23+
24+
}
25+
*head = prev; //assigning the address the updated value
26+
}
27+
1228
void printList(struct node *t){
1329
if(t){
1430
//interchanging these lines will print it in reverse order
@@ -41,20 +57,7 @@ int main(){
4157
printList(t);
4258
t = head;
4359

44-
//reversing the list
45-
struct node *curr, *prev,*nextNode;
46-
curr = head;
47-
48-
prev = NULL;
49-
while(curr){
50-
nextNode = curr->link;
51-
curr->link = prev;
52-
prev = curr;
53-
curr = nextNode;
54-
55-
}
56-
head = prev;
57-
60+
reverse(&head); //passing the address of the pointer pointing to the first address of the linked list
5861
printList(head);
5962

6063
}

0 commit comments

Comments
 (0)