Skip to content

Commit d77711e

Browse files
committed
Updated Single Linked List
1 parent 584b174 commit d77711e

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Data Structures/Linked Lists/Singly Linked List/Reverse_Nodes_in_K_Groups.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@ void printList(ListNode* head){
4242
ListNode* reverseKGroup(ListNode* head, int k) {
4343
ListNode* curr = head;
4444
int count = 0;
45+
46+
//Take first k group of nodes
4547
while (curr != NULL && count != k) {
4648
curr = curr->next;
4749
count++;
4850
}
51+
4952
if (count == k) {
53+
//Recursively taking all k group of nodes
54+
//Passing next group first node as curr
5055
curr = reverseKGroup(curr, k);
56+
57+
//Go on reversing the node group using normal reverse steps
5158
while (count-- > 0) {
5259
ListNode* tmp = head->next;
5360
head->next = curr;

0 commit comments

Comments
 (0)