4-- reverse problem list doubly linked list

topic

Function for reversing a two-way linked list


Claim

If the chain length is N, the time complexity requirements of O (N), additional space requirements complexity O (1).


Source

public class Node{
	public int value;
	public Node next;
	public Node last;
	public Node(int data){
		this.value=data;
	} 
}

public Node reverseList(Node head){
	Node pre=null;
	Node next=null;
	while(head!=null){
		next=head.next;
		head.next=pre;
		head.last=next;
		pre=head;
		head=next;
	}
	return pre;
	
}

 

Published 43 original articles · won praise 21 · views 4917

Guess you like

Origin blog.csdn.net/flying_1314/article/details/103837512