Question: (Python) Suppose a queue is being used to store numbers, and we want to see if the numbers currently in the queue are in order.

(Python) Suppose a queue is being used to store numbers, and we want to see if the numbers currently in the queue are in order. Write and test a function queueInOrder(someQueue) that returns a Boolean indicating whether someQueue is in sorted order. After calling the function, the queue should look exactly like it did before the function call. Your function should only make use of the available queue ADT operations; accessing the underlying representation is not allowed.

#---------------------------------------------------------------------- class Queue: #---------------------------------------------------------------------- def __init__(self): '''create an empty FIFO queue''' self.q = [] #---------------------------------------------------------------------- def size(self): '''return number of items in the queue pre: none post: returns number of items in the queue''' return len(self.q) #---------------------------------------------------------------------- def enqueue(self, x): '''insert x at end of queue pre: none post: x is added to the queue''' self.q.append(x) #---------------------------------------------------------------------- def front(self): '''return first item in queue pre: queue is not empty; IndexError is raised if empty post: returns first item in the queue''' return self.q[0] #---------------------------------------------------------------------- def dequeue(self): '''remove and return first item in queue pre: queue is not empty; IndexError is raised if empty post: removes and returns first item in the queue''' return self.q.pop(0) #----------------------------------------------------------------------

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 Databases Questions!