Hi there,
I got a small problem with a java method I've written.
Its a swap method which should swap two elements of a dual linked list (meaning each element has a 'next' and a 'previous' link, thus you can cycle through the list in two directions).
The problem is: The resulting list contains a cycle, thus there is no head element.
The code is:
private void swap(List a, List b)
{
List temp = a;
if(a.previous != null)
a.previous.next = b;
if(a.next != null)
a.next.previous = b;
if(b.previous != null)
b.previous.next = a;
if(b.next != null)
b.next.previous = a;
a.next = b.next;
a.previous = b.previous;
b.next = temp.next;
b.previous = temp.previous;
}
Anyone has an idea what I'm doing wrong here?
Thanks in advance for any hints!