Reverse the Linked List. Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL

Mighty96

BANNED
Joined
Sep 9, 2018
Messages
16
Reaction score
10
Assume that we have linked list 1 → 2 → 3 → Ø, we would like to change it to Ø ← 1 ← 2 ← 3. While you travel the linked list, change the current node's next pointer to point to its previous element. reference to the previous nodes should be stored into a temp variable as shown so that we don’t lose track of the swapped node.
 
Is that a homework I see young genleman?
Also, linked list syntax is language specific, so which one of those that still use raw pointers do you use? Or don't tell me, you're working with an(oh woe, oh sorrow) objectified linked list in a mostrosity such as Java?
Importantnly let me point out that there is a Programming forum in the depths bellow. It is a bit dusty and all as most of the IM's here use ready made tools and just a few rare exceptions are willing to get their hands dirty with the cogs and oil of the programming. (For quite a many it is a bad ROI after all, programming is a beautiful but terrible beast) Your question might be better suited there.
Finally, there are specialized programming forums out there, in the wild. In the places we don't talk about. Since I can't post links yet I can only tell you the legends about them so try to open ye olde google. You will find a plethora of spaces that already solved your question many times over.
 
Back
Top