PLEASE COMPLETE THIS PYTHON PROGRAM BY FILLING OUT FOLLOWING BLANKS AND ALSO ATTACH class Node(object): # Singly linked node def __init__(self, data=None, next=None, prev=None): self.data = _____ self.next = _____ self.prev = _______ class doubly_linked_list(object): def __init__(self): self.head =______ _________= None self.count = 0 def append_item(self, data): # Append an item new_item = Node(data, None, None) if _______________: self.head = new_item self.tail = self.head else: new_item.prev = self.tail self.tail.next = _______ self.tail = new_item self.count += 1 def iter(self): # Iterate the list current = ________ while current: item_val = current.data current = current.next yield item_val def print_foward(self): for node in self._____(): print(node) def search_item(self, val): for node in self.iter(): if val == node: return True return False items = doubly_linked_list() items.append_item('PHP') items.append_item('Python') items.append_item('C#') items.append_item('C++') items.append_item('Java') items.append_item('SQL') print("Original list:") items.print_foward() print("\n") if items.search_item('SQL'): print("True") else: print("False") if items._________('C+'): print("True") else: print("False")
PLEASE COMPLETE THIS PYTHON PROGRAM BY FILLING OUT FOLLOWING BLANKS AND ALSO ATTACH
class Node(object):
# Singly linked node
def __init__(self, data=None, next=None, prev=None):
self.data = _____
self.next = _____
self.prev = _______
class doubly_linked_list(object):
def __init__(self):
self.head =______
_________= None
self.count = 0
def append_item(self, data):
# Append an item
new_item = Node(data, None, None)
if _______________:
self.head = new_item
self.tail = self.head
else:
new_item.prev = self.tail
self.tail.next = _______
self.tail = new_item
self.count += 1
def iter(self):
# Iterate the list
current = ________
while current:
item_val = current.data
current = current.next
yield item_val
def print_foward(self):
for node in self._____():
print(node)
def search_item(self, val):
for node in self.iter():
if val == node:
return True
return False
items = doubly_linked_list()
items.append_item('PHP')
items.append_item('Python')
items.append_item('C#')
items.append_item('C++')
items.append_item('Java')
items.append_item('SQL')
print("Original list:")
items.print_foward()
print("\n")
if items.search_item('SQL'):
print("True")
else:
print("False")
if items._________('C+'):
print("True")
else:
print("False")
Step by step
Solved in 2 steps with 2 images