I am learning linked list and I'm creating doubly linked list. My print backward is not working as intended. For better Information I will highlight the print backward function.
Print Backward
class Node:
def __init__(self, data=None, next=None, prev=None):
self.data = data
self.next = next
self.prev = prev
class LinkedList:
def __init__(self):
self.head = None
def get_last_node(self):
itr = self.head
while itr.next:
itr = itr.next
return itr
def print_backward(self):
if self.head is None:
print("Linked List is empty")
return
last = self.get_last_node()
itr = last
llstr = ''
while itr:
llstr += itr.data + '-->'
itr = itr.prev
print(llstr)
I hope that my code can be resolved...