Answered step by step
Verified Expert Solution
Question
1 Approved Answer
USING PYTHON 3: Complete the Class/def Dequeue(self) class Node(object): A node is a simple container with two pieces of information data: the contained information
USING PYTHON 3: Complete the Class/def Dequeue(self) class Node(object): """ A node is a simple container with two pieces of information data: the contained information next: a reference to another node We can create node-chains of any size. """ def __init__(self, data, next=None): """ Create a new node for the given data. Pre-conditions: data: Any data value to be stored in the node next: Another node (or None, by default) """ self._data = data self._next = next if __name__ == "__main__": anode = Node(1) bnode = Node(1,anode) print("Are anode and bnode the same instance?", anode is bnode) print("Do anode and bnode have the same data?", anode._data == bnode._data) bnode._data = 3 print("Do anode and bnode have the same data?", anode._data == bnode._data) print(bnode._next==anode)
############################################################################
import Node as Node class Queue(object): def __init__(self): """ Purpose creates an empty queue """ self.__size = 0 # how many elements in the queue self.__first = None # the node chain starts here self.__last = None # the node chain ends here def is_empty(self): """ Purpose checks if the given queue has no data in it Pre-conditions: queue is a queue created by create() Return: True if the queue has no data, or false otherwise """ return self.__size == 0 def size(self): """ Purpose returns the number of data values in the given queue Pre-conditions: queue: a queue created by create() Return: The number of data values in the queue """ return self.__size def enqueue(self, value): """ Purpose adds the given data value to the given queue Pre-conditions: queue: a queue created by create() value: data to be added Post-condition: the value is added to the queue Return: (none) """ n = Node.Node(value) if self.is_empty(): self.__first = n self.__last = n else: prev_last_node = self.__last prev_last_node._next = n self.__last = n self.__size += 1 def dequeue(self): """ Purpose removes and returns a data value from the given queue Post-condition: the first value is removed from the queue Return: the first value in the queue, or None """ COMPLETE THIS ONE!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started