fixed reverse double linked list code
This commit is contained in:
parent
8c5f7a20d8
commit
ccf2b7002c
|
|
@ -3,3 +3,4 @@
|
||||||
*.inp
|
*.inp
|
||||||
*.oac
|
*.oac
|
||||||
*.out
|
*.out
|
||||||
|
*.pdf
|
||||||
|
|
|
||||||
|
|
@ -67,14 +67,14 @@ public class Solution {
|
||||||
*/
|
*/
|
||||||
static DoublyLinkedListNode reverse(DoublyLinkedListNode head) {
|
static DoublyLinkedListNode reverse(DoublyLinkedListNode head) {
|
||||||
|
|
||||||
if (head == null) return null;
|
while (head != null) {
|
||||||
head.prev = head.next;
|
DoublyLinkedListNode temp = current.prev;
|
||||||
head.next = null;
|
current.prev = current.next;
|
||||||
while (head.prev != null){
|
current.next = temp;
|
||||||
head = head.prev;
|
current = current.prev;
|
||||||
DoublyLinkedListNode temp = head.next;
|
}
|
||||||
head.next = head.prev;
|
if(temp != null){
|
||||||
head.prev = temp;
|
head = temp.prev;
|
||||||
}
|
}
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue