package ReverseListNode;public class ReverseNode public class ListNode private ListNode next; private ListNode prev; public void ReverseNodeListNode headListNode tail i
package ReverseListNode;
public class ReverseNode { public class ListNode{ private ListNode next; private ListNode prev; }
public void reverseNode(ListNode head, ListNode tail){
ListNode front = head;
ListNode behind = tail;
while(front != null && behind != null && front != behind && front.prev != behind){
ListNode frontNext = front.next;
ListNode behindPrev = behind.prev;
// Swap front and behind
ListNode tempNext = frontNext;
ListNode tempPrev = behindPrev;
front.next = behind.next;
front.prev = behindPrev;
behind.next = tempNext;
behind.prev = front.prev;
frontNext.prev = behind;
behindPrev.next = front;
// Move pointers
front = front.next;
behind = behind.prev;
}
}
public static void main(String[] args) {
}
原文地址: https://www.cveoy.top/t/topic/iggS 著作权归作者所有。请勿转载和采集!