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
*.oac
*.out
*.pdf

View File

@ -67,14 +67,14 @@ public class Solution {
*/
static DoublyLinkedListNode reverse(DoublyLinkedListNode head) {
if (head == null) return null;
head.prev = head.next;
head.next = null;
while (head.prev != null){
head = head.prev;
DoublyLinkedListNode temp = head.next;
head.next = head.prev;
head.prev = temp;
while (head != null) {
DoublyLinkedListNode temp = current.prev;
current.prev = current.next;
current.next = temp;
current = current.prev;
}
if(temp != null){
head = temp.prev;
}
return head;
}