Home > Video > Details
Full Screen
This solution is helpful, I Like it. 5 Views: 681

Hello guys,

In an attempt to understand the Algorithm that reverses the Linked List, I wanted to see if I could explain this to someone else. Keep in mind, that I was trying to understand the algorithm myself, let me know in the comments below if this confused you as much as I tried to make sense of it.

I found reversing a Linked List confusing when it is quite manageable to understand, the idea is that you:

1. Create 3 Node Variables: next, prev, and current
2. Use next and prev to keep track of the nodes you before you change them

3. Flip the pointer of current.next to point to prev [This is important]
4. Move current into the prev variable (in order to free up current to be assigned to the next)
5. Make next as current (This makes sense because we moved current into prev, now we're making next as current)
6. Relink the prev to have it's previous node pointing to the next

Reverse a Linked List in C#

Algorithms Study Notes,Data structure,Trees,LinkedList,

Edit Video
If you log in, you will be notified when someone leaves a comment.

Other users would like to know if this solution helped you.

Jack said:

Thank you for explaining, this was confusing to me as well.

Posted On: August 06, 2022 14:10:36 PM

© 2022 - ErnesTech - Privacy