反转单向双向链表

class Node{
	int value;
	Node next;
	Node ref;
	
	public Node(int value){
		this.value = value;
	}
}
public class ReverseList {

	public static Node reverseList(Node head){
		Node oldNext = null;
		Node newNext = null;
		while(head.next!=null){
			oldNext = head.next;
			head.next = newNext;
			newNext = head;
			head = oldNext;
		}
		head.next = newNext;
		
		return head;
	}
	
	public static Node reverseDoubleList(Node head){
		Node oldNext = null;
		Node ref = null;
		
		while(head.next!=null){
			oldNext = head.next;
			head.next = ref;
			head.ref = oldNext;
			
			ref = head;
			head = oldNext;
			
		}
		head.next = ref;
		head.ref = null;
		
		return head;
		
	}
}

猜你喜欢

转载自blog.csdn.net/liu_xiansen/article/details/82968133