Adobe Interview Question
node structure ->
1. previous node link called previous
2. next node link called next
3. data
---------------
Algo:
1. start
2. set temp to next
3. set next to prev
4. set prev to temp
5. advance current position (var pointing to the current position in the list) to next node
6. start from step 2 again
node structure ->
1. previous node link called previous
2. next node link called next
3. data
---------------
Algo:
1. start
2. set temp to next
3. set next to prev
4. set prev to temp
5. advance current position (var pointing to the current position in the list) to next node
6. start from step 2 again
def reverseDoublyLinkedList(head):
# head far left end, 0 or 1 node
if head == None or (head.next==None and head.back==None):
return
cur = head
# while there is another node to the right. swap the pointer values, assumes valid lists.
while cur:
tmp = cur.next
cur.next = cur.back
cur.back = tmp
cur = tmp
- Vir Pratap Uttam May 08, 2015