Skip to content

Commit e26c07a

Browse files
committed
Reversing Linked List
1 parent a6b571f commit e26c07a

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

DataStructures/LinkedList/linkedlist

40 Bytes
Binary file not shown.

DataStructures/LinkedList/linkedlist.cpp

+16-1
Original file line numberDiff line numberDiff line change
@@ -211,9 +211,24 @@ node * mergesortLL(node* head){
211211

212212
}
213213

214+
node* reverseLL(node* head){
215+
if(head == NULL || head->next == NULL)
216+
return head;
217+
218+
node* small = reverseLL(head->next);
219+
220+
node* temp = small;
221+
while(temp->next != NULL){
222+
temp = temp->next;
223+
}
224+
temp->next = head;
225+
head->next = NULL;
226+
227+
return small;
228+
}
214229
int main(){
215230
node *head = takeinput2();
216231

217-
node* h = mergesortLL(head);
232+
node* h =reverseLL(head);
218233
print(h);
219234
}

0 commit comments

Comments
 (0)