edumeister_logo

q3_test.docx-current = current.next # returns theshowing page 3-4 out of 4

Upload your course documents to receive views for accessing documents on Edumeister.

Upload documents to earn views.
current = current.next
# returns the size of the doubly linked list
def size(self):
count = 0
current = self.head
while current is not None:
count = count + 1
current = current.next
return count
# returns True if the doubly linked list is empty, False otherwise
def is_empty(self):
return self.head is None
# returns a string representation of the list, from head to tail
# each piece of data is separated by "->"
def __str__(self):
output = []
current = self.head
while current:
output.append(current.data)
current = current.next
return "->".join(output)
# returns a string representation of the list, from tail to head
# each piece of data is separated by "<-"
def reverse_string(self):
output = []
current = self.tail
while current:
output.append(current.data)
current = current.prev
return "<-".join(output)
dll = Doubly_Linked_List()
dll.add("A")
dll.add("B")
dll.append("C")
dll.append("D")
dll.insert(1, "E")
dll.insert(0, "F")
print(dll)
print(dll.reverse_string())
print("The DLL contains", dll.size(), "nodes")
print(dll.pop(0))
dll.remove("D")
print(dll)
print(dll.reverse_string())
while not dll.is_empty():
print(dll.size())
print(dll.pop())
#TAT_list = Doubly_Linked_List()
#TAT_list.add("A")
#TAT_list.add("B")
#TAT_list.add("C")
#TAT_list.remove("D")
#TAT_list.add("D")
#TAT_list.add("E")
#TAT_list.add("F")
#print(TAT_list)
#TAT_list.insert(2,"X")
#print(TAT_list)
#TAT_list.reverse_string()
#print(TAT_list.reverse_string())
#TAT_list.remove("B")
#print(TAT_list.pop())
#print(TAT_list)
#print(TAT_list)
#print(TAT_list.size())