19CSE212-CSEB-2023-QUEUE


Submit solution

Points: 25
Time limit: 10.0s
Memory limit: 64M

Author:
Problem type
Allowed languages
Python

PROBLEM STATEMENT

This is a simple data structures problem. Your goal is to write the queue Array ADT and implement the following functions.

Input:
  • First line contains integer S, is the size of the queue.
  • Second line contains integer N, is the number of operations in the test case.
  • Next M line will include the series of operations of the following type Character, value,
  • Where character indicates the queue operation E-enqueue, D-dequeue, F-front position, R-rear reposition, Fr - value at front, S-size, I-isempty, EK - enqueue at kth position in the queue, M-Merge 2 queues.
  • For enqueue, it is followed by a value, others will not be followed by a value.
  • For enqueueKth, it is followed by two values, first is the position(k) in which you want to insert and second is the value you want to insert
  • Merge two sorted Queue Q1, and Q2 to form a third Queue Q3(Need not retain Q1 and Q2)
    • Reads in maximum sizes of the two queues
    • Then input number of enqueues made for first sorted queue
    • Followed by that enter the values into queue 1 in sorted order
    • Then input number of enqueues made for second sorted queue
    • Followed by that enter the values into queue 2 in sorted order
Output:

For each testcase, output the result of each operation separated by a newline.

  • The output of enqueue should be the content of the queue (note: print function is given).
  • The output of enqueueKth should be the content of queue, and if the value of k is exceeding the size of the queue then it should print No such position case sensitive followed by content of queue in the next line.
  • Merge Queue, output the result of merging two sorted queue which should be sorted.
  • Dequeue should output the returned value,
  • front the value on front,
  • size the size of the queue, and
  • isEmpty should return true or false.
  • If queue full when enqueue, return Queue Full Exception case sensitive. (don't print the queue)
  • If queue empty when dequeue or top, return Queue Empty Exception case sensitive.
Constraints
  • 1 <= S <= 20
  • 10 <= N <= 100
Sample Input
  5
  12
  E 1 
  E 2 
  E 3 
  EK 0 0  -*Enqueue at 0th position element 0*
  EK 2 10  -*Enqueue at 2nd position element 10*
  F
  R
  EK 4 30
  M  -*Merge*
  10  -*Queue 1 maximum size*
  10 - *Queue 2 maximum size*
  5 - *Number of enqueue operations to be done in queue1 and Following 5 lines are the Queue 1 content*
  1
  2
  3
  4
  5
  3 -*Number of enqueue operations to be done in queue2 and Following 3 lines are the Queue 2 content*
  6
  7
  8
  M   -*Merge*
  10  -*Queue1 Maximum size*
  5   - *Queue 2 maximum size*
  8   - *Number of enqueue operations to be done in queue1 and Following 8 lines are the Queue 1 content*
  1
  2
  3
  4
  5
  6
  7
  8
  3 -*Number of enqueue operations to be done in queue2 and Following 3 lines are the Queue 2 content*
  9
  10
  11
  D
  EK 7 10
Sample Output
  1
  1 2
  1 2 3
  0 1 2 3 
  0 1 10 2 3 
  0
  4
  Queue Full Exception
  0 1 10 2 3
  1 2 3 4 5 6 7 8 -*Result of merging*
  1 2 3 4 5 6 7 8 9 10 11 -*Result of merging*
  0
  No Such Position
  0 1 10 2 3

Note on Sample Input

the following are not part of the input. It is gives the explanation to input line.

  • Merge
  • Enqueue at 0th position element 0
  • Enqueue at 2nd position element 10
  • Queue 1 size
  • Queue 2 size
  • Number of enqueue operations to be done in queue1 and Following 5 lines is the Queue 1 content
  • Number of enqueue operations to be done in queue1 and Following 3 lines is the Queue 2 content

For example, In EK 0 0 - Enqueue at 0th position element 0, "- Enqueue at 0th position element 0" explains the operation EK 0 0

####Code Template
class MyQueue():

    def __init__(self,size):
        # this is the queue container called 'queue'
        self.queue = []
        # front and back indexes
        self.f = 0
        self.r = -1
        # define the queue size 'max_queue_size' and initialize it
        self.max_queue_size = size
        for i in range(0,self.max_queue_size):
            self.queue.append(None)
        self.sz=0

    def enqueue(self, value):
        return


    def dequeue(self):
        return       

    # returns front element without removing it if the queue is not empty, else throws exception   
    def frontelement(self):
        return

    # returns True if queue is empty
    def isEmpty(self):
        return

    # returns the number of elements currently in queue     
    def size(self):
        return


    def printQueue(self):
        if (self.isEmpty()):
            print ("Empty")
        else:
            for i in range(self.max_queue_size):
                if self.queue[i]!=None:
                    print(self.queue[i],end=" ")
            print(" ")


# Driver code.---------------------------------------------

def testqueue():
    qsize=int(input())
    q1 = MyQueue(qsize)
    inputs=int(input())
    while inputs>0:
        command=input()
        operation=command.split()
        if(operation[0]=="S"):
            print(q1.size())
        elif(operation[0]=="I"):
            print(q1.isEmpty())
        elif(operation[0]=="E"):
            q1.enqueue(int(operation[1]))
        elif(operation[0]=="D"):
            print(q1.dequeue())
        elif(operation[0]=="Fr"):
            print(q1.frontelement())
        elif(operation[0]=="DK"):
            st1.delK(int(operation[1]))
        inputs-=1

def main():
    testqueue()

if __name__ == '__main__':
    main()




Comments

There are no comments at the moment.