Doubly Linked List reverse Why I cann't reverse twice# JobHunting - 待字闺中
s*d
1 楼
public void reverse(){
DoubleNode start=head;
DoubleNode temp=null;
while(head!=null){
temp=head.getNext();
head.setNext(head.prev);
head.setPrev(temp);
if(head.getPrev()==null){
head.setPrev(start);
break;
}
head=head.getPrev();
}
}
If I reverse onece, it prints successfully. While I reverse again, it prints
nothing.
Appreciate your help!
DoubleNode start=head;
DoubleNode temp=null;
while(head!=null){
temp=head.getNext();
head.setNext(head.prev);
head.setPrev(temp);
if(head.getPrev()==null){
head.setPrev(start);
break;
}
head=head.getPrev();
}
}
If I reverse onece, it prints successfully. While I reverse again, it prints
nothing.
Appreciate your help!