Skip to content

Commit c71b2d4

Browse files
committed
adding more comments for reverse recursive fn
1 parent 3e1bffd commit c71b2d4

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

OneWayLinkedList.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,14 +313,20 @@ void OneWayLinkedList::reverse() {
313313
this->head = prev;
314314
}
315315

316+
// Reverse the list with a recursive function
316317
void OneWayLinkedList::reverseRecursive(Node* node) {
318+
// If the node is the last node
317319
if (node->next == NULL) {
318320
this->head = node;
319321
return;
320322
}
323+
// Reverse the rest of the list
321324
reverseRecursive(node->next);
325+
// Reverse the current node
322326
Node* next = node->next;
323327
next->next = node;
328+
329+
// Set the next node to NULL
324330
node->next = NULL;
325331
}
326332

0 commit comments

Comments
 (0)