October 2004
Intermediate to advanced
336 pages
6h 27m
English
This function reverses a singly linked list by walking the list and changing pointers.
Each element in the list is an instance of a class ListNode. The list itself is an instance of a class List. ListNode has a next member that points to the next element on the list. The final element on the list has a next pointer equal to null.
List has a method called Reverse(), which is the method to reverse the linked list.
1. class ListNode { 2. 3. private int value; 4. protected ListNode next; 5. 6. public ListNode(int v) { 7. value = v; 8. next = null; 9. } 10. 11. public ListNode(int v, ListNode n) { 12. value = v; ...
Read now
Unlock full access