Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

[PYTHON] I can\'t change the __init__ so Im having trouble with making my code w

ID: 3741585 • Letter: #

Question

[PYTHON]

I can't change the __init__ so Im having trouble with making my code work. The code must be able to return the same values exactly as the example given. Above is the code that needs to be folloed except for the parts that says (#Write your code here)

Thank you <3

CMPSC-122: Intermediate Programming Spring 2018 Lab #11 Due Date: 04/06/2018, 11:59PM Instructions The work in this lab must be completed alone If you need guidance, attend to your recitation class. Read the "Submitting assignments to Vocareum" file for instructions on how to submit this lab Do not change the function names or given code on your script The file name must be LAB11.py incorrect name files will get a 0 score) You are responsible for testing your code. Use python -i LAB11.py in your terminal (or command prompt) to provide input to your functions. Test with as many data as you feel comfortable - - Each function must return the output (Do not use print in your final submission) - Do not include test code outside any function in the upload. Remove all y our testing code before uploading your file. If you are using input0 to insert values in your functions and print to see the values, remove them. xercise 1 [10 pts] NOTE: There is no partial credit for methods that do not workproperly. You must ensure the entire code works after the addition of new methods In class, we discussed the abstract data type Queue. A queue is a collection of items where the addition of new items happens at one end (tail) and the removal of existing items occurs at the other end (head) (FIFO). Implement the queue data structure with the following operations Queue0 creates a new queue that is empty. It needs no parameters and returns nothing enqueue(item) adds a new Node with value-item to the tail of the queue. It needs the value of the Node and returns nothing. [3 pts] dequeueO removes the head Node from the queue. It needs no parameters and returns the value of the Node removed from the queue. The queue is modified. [3 pts] isEmpty0 tests to see whether the queue is empty. It needs no parameters and returns a boolean value. [2 pts] sizeO returns the number of items in the queue. It needs no parameters and returns an integer. [2 pts]

Explanation / Answer

class Node: def __init__(self, value): self.value = value self.next = None def getValue(self): return self.value def getNext(self): return self.next def setValue(self, new_value): self.value = new_value def setNext(self, new_next): self.next = new_next def __str__(self): return ("{}".format(self.value)) __repr__ = __str__ class Queue: def __init__(self): self.count = 0 self.head = None self.tail = None def isEmpty(self): return self.count == 0 def size(self): return self.count def enqueue(self, item): temp = Node(item) if self.head is None: self.head = temp self.tail = temp else: self.tail.next = temp self.tail = temp self.count += 1 def dequeue(self): if self.head is not None: x = self.head self.head = self.head.next self.count -= 1 if self.count == 0: self.tail = None return x else: return "Queue is Empty" def printQueue(self): temp = self.head while temp is not None: print(temp.value, end=' ') temp = temp.next if __name__ == '__main__': queue = Queue() print(queue.isEmpty()) queue.enqueue(1) queue.enqueue(2) queue.enqueue(3) queue.enqueue(4) print(queue.printQueue()) print(queue.isEmpty()) print(queue.size()) print(queue.dequeue()) print(queue.dequeue()) print(queue.dequeue()) print(queue.dequeue()) print(queue.dequeue()) queue.enqueue(3) queue.enqueue(2) print(queue.printQueue()) print(queue.dequeue()) print(queue.printQueue())

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote