Implement Queue using Array
Learning DSA practice problem on Onlearn.
Difficulty: easy.
Topics: Implementing Queue Data Structure using Array with all basic functions, Queue, Arrays, Data Structures, Time Complexity, Space Complexity, Modular Arithmetic, complexity analysis, edge cases, array, queue, general programming, data structures, Queue (FIFO), Queue Operations.
Implement Queue using Array Problem Statement Implement a Queue data structure using an array. Your implementation should support the following operations: push(element): Adds element to the rear of the queue. pop(): Removes and returns the element from the front of the queue. top(): Returns the element at the front of the queue without removing it. size(): Returns the number of elements currently in the queue. isEmpty(): Returns true if the queue is empty, false otherwise. isFull(): Returns true if the queue is full, false otherwise. The queue should have a fixed maximum capacity. When the queue is full, push should indicate an error. When the queue is empty, pop or top should indicate an error. Input Specification The input will consist of a series of operations. Each operation will be one of the following: push X: Push integer X into the queue. pop: Pop an element from the queue. top: Get the front element of the queue. size: Get the current size of the queue. Output Specification For each push operation, print a message indicating the element pushed. For pop, print the element popped. For top, print the top element. For size, print the current size. Handle error cases for pop, top when the queue is empty, and push when the queue is full. Constraints The maximum size of the queue (N) will be between 1 and 10^5. The number of operations (Q) will be between 1 and 10^5. Elements pushed into the queue will be integers between 10^9 and 10^9. Sample Test Case Input: Expected Output: