Advertisement
Aldin_SXR

Untitled

Feb 27th, 2024
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1.     public void reverse() {
  2.         Node<Data> current = head;                                              // 1
  3.         Node<Data> previous = null;                                             // 1
  4.  
  5.         while (current != null) {                                               // 2
  6.             Node<Data> next = current.next;                                     // 3
  7.             current.next = previous;                                            // 4
  8.             previous = current;                                                 // 5
  9.             current = next;                                                     // 6
  10.         }
  11.         head = previous;                                                        // 7
  12.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement