Doubly linked list, reverse()
Hi. I have a Doubly-linked list and i need to reverse it. I'm not sure if the method that i wrote works. It's a lil bit tricky. Would you plz correct this method if there is any thing wrong with this code?
Appreciate it
public void reverse()
{
if (first == null)
return;
DoubleNode previous = first;
DoubleNode current = first.next;
first.next = null;
while (current != null)
{
DoubleNode next = current.next;
current.next = previous;
previous = current;
current = next;
}
first = previous;
}