-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
33 lines (30 loc) · 808 Bytes
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#
# Complete the 'reverse' function below.
#
# The function is expected to return an INTEGER_DOUBLY_LINKED_LIST.
# The function accepts INTEGER_DOUBLY_LINKED_LIST llist as parameter.
#
#
# For your reference:
#
# DoublyLinkedListNode:
# int data
# DoublyLinkedListNode next
# DoublyLinkedListNode prev
#
#
def reverse(llist):
if llist.next is None:
return llist
else:
curr = llist
curr_newList = DoublyLinkedListNode(curr.data)
curr_newList.next = None
while True:
if curr.next is None:
break
curr_newList.prev = DoublyLinkedListNode(curr.next.data)
curr_newList.prev.next = curr_newList
curr_newList = curr_newList.prev
curr = curr.next
return curr_newList