DEV Community

Paolo Ventura
Paolo Ventura

Posted on

100 algos in 100 days (Day 29)

[16/10] A bit of a gap over the last 3 days with some stuff going on.
I started really looking into Linked Lists. Coming from JS we hardly ever use this data structure but in .NET it is quite common so really cool to know more.

Question

Reverse a linked list in place

This was a cool trick to not go all the way through. As long as you keep track of previous, current and next you can do it all there and then.
Something like this pseudo code:

// Copy a pointer to the next element
// before we overwrite currentNode.next
// Reverse the 'next' pointer
// Step forward in the list
Enter fullscreen mode Exit fullscreen mode

Top comments (0)