Question: node.py class Node ( object ) : Represents a singly linked node. def _ _ init _ _ ( self , data,

node.py
class Node(object):
"""Represents a singly linked node."""
def __init__(self, data, next=None):
"""Instantiates a Node with a default next of None."""
self.data = data
self.next = next
'''
def main():
node1= None
node2= Node("A", None)
node3= Node("B", node2)
print(node2.data)
print(node3.data)
#print(node1.data) error
nodel=Node("C", node3)
print(nodel.data)
if __name__=="__main__":
main()
LinkQueue.py
# linked Queue
from node import Node
class LinkedQueue(object):
def __init__(self):
self.front = self.rear = None
def isEmpty(self):
return (self.front == None) # or you could ask for both
def add(self, item):
node = Node(item)
if self.isEmpty():
self.front = self.rear = node
return
self.rear.next = node
self.rear = node
def pop(self):
if self.isEmpty():
return None
value = self.front.data
self.front = self.front.next
if self.front == None:
self.rear = None
return value
def getFront(self):
if self.front == None:
return None
return self.front.data
def getRear(self):
if self.rear == None:
return None
return self.rear.data
def __str__(self):
probe = self.front
st = "queue: "
while probe != None:
st = st + str(probe.data)+"1"
probe = probe.next
return st
# driver
def main():
queue = LinkedQueue()
print(queue) # Print the queue
queue.add(10) # Add 10
queue.add(15) # Add 15
queue.add(20) # Add 20
print(queue) # Print the queue
queue.pop() # Remove
queue.pop() # Remove
print(queue) # Print the queue
queue.add(30) # Add 30
queue.add(40) # Add 40
print(queue) # Print the queue
print("Front:", queue.getFront()) # Get the front
print("Rear:", queue.getRear()) # Get the rear
if __name__=="__main__":
main()
Create a python code for computer science student that is python beginner with this infomation: Chose an object from real life that is normally placed in a queue. Ex: call center
Create a class for that object and in addition to the constructor, __init__, also write the method for the display __str__. Create several of this object by instantiating the class in main and placed them in the queue. Use the queue class that we wrote in class. If you use another queue class because you were absent, give credit to the author to follow the honor code. Add your objects, remove them, and print your removed objects. Print the final front object and print the rear object.
You will need your node.py if you use the class code, your queue python file, and your new class file that you are creating. You new file can have the imports and the main.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!