fixed reverse double linked list code

This commit is contained in:
anebz 2019-08-12 20:01:19 +02:00
parent 8c5f7a20d8
commit ccf2b7002c
2 changed files with 9 additions and 8 deletions

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
*.inp *.inp
*.oac *.oac
*.out *.out
*.pdf

View File

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