Reversing A Linked List In 60 Characters
Reversing a linked list by swapping `next` pointers. Iterate through the list, saving `current.next` in `next`, then swap `current.next` with `prev`. Repeat until `current.next` is null.
the core is prev pointer is storing the current while(current){ next = current.next current.next = prev prev = current current = next } let discuss the part [0,1,2,3,4] **prev = null current = {data:0,next:1} next = null** saving current.next in next (later use) current = {data:0,next:1} current.next contains {data:1,next:2} current.next = prev {null} now current modified {data:0,next:1} to {data:0,next:null} prev = current so prev is null to {data:0,next:null} current = next // now next stores the {data:1,next:2} // next iteration current = {data:1,next:2} next =...