Functions and Recursions – Arithmetic – Problem #18

IIT Kharagpur CS10001 / CS11001 Programming and Data Structures Lab Question Archive

Difficulty: hard

Problem Statement

Write a program to implement a queue using structures. In queue, you have two ends, namely ‘front’ and ‘rear’. The elements can be inserted at the rear end and can be removed from the front end. Hence, the element, that you have inserted first, will be removed first (First In First Out). Write a menu driven program to implement a queue using structures. The structure will contain the list of elements (of size MAX) and the index of the front and rear element. Implement enque() and deque() operations. Enque() function will take the input from the user and insert the element in the queue. Deque() removes the element from the queue, also prints the removed element. Print the state of the queue after enque and deque operation. Please remember, during enque(), the newly inserted element will be the rear element. During deque(), the front element will be removed. Take all the input and print all the output inside the main() only. The code should handle the overflow and underflow too. Example: Enter the option: 1. Enque, 2. Deque 2 The queue is empty! Enter the option: 1. Enque, 2. Deque, 3. Exit 1 Enter the element: 5 The queue contains 5 Enter the option: 1. Enque, 2. Deque 3. Exit 1 Enter the element:12 The queue contains 5, 12 Enter the option: 1. Enque, 2. Deque 3. Exit 1 Enter the element: 7 The queue contains 5, 12, 7 Enter the option: 1. Enque, 2. Deque 3. Exit 2 Removed element 5 The queue contains 12, 7

Back to Lab Problems
Functions and Recursions/Arithmetic/Problem #18

Lab Problem Statement

Specifications & Problem DetailsIIT Kharagpur PDS Archive
Loading question...

Interactive C Compiler · Problem #18

WASM In-Browser

Runs directly on your machine · Zero remote server dependency

Compiler downloads on first Run (large, saved in your browser after that)
main.cCtrl + Enter to run
1
2
3
4
5
6
7
Input (stdin)given to scanf / cin
Output

Output appears here. Press Run to compile and execute.