Download presentation
Presentation is loading. Please wait.
1
Linked List Recursion
2
Recursion Recursion recipe Base case: “Oh I know the answer”
General case: “I know who to ask for the answer” OR “I know part of the answer and who to ask about the rest”
3
LL Base Cases Linked Lists base case options: Have a link to last node
current->next == nullptr Have an element to work with Have a nullptr Gracefully handles empty list
4
LL General Case Have a pointer, and 1+ nodes off next
Work with current Recursive call to current->next
5
Functions Recursive print:
6
Functions Recursive get length: https://goo.gl/hMmVVX
nullptr base case gives right answer for empty list
7
Functions Recursive getLast https://goo.gl/hMmVVX
Makes no sense on empty list
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.