public void swapPairs() {
ListNode temp = this;
ListNode dummy = this;
while (temp.next != null) {
temp.next = temp.next.next;
dummy.next.next = temp;
temp = temp.next;
dummy = dummy.next;
}
}
I'm essentially trying to use this method on a LL head node, and have it swap adjacent pairs such that (1,2,3,4) -> (2,1,4,3)
The logic of the method seems consistent to me but it's not working.