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;
}