08 AshleshKadam21
08 AshleshKadam21
Experiment No 21
Algorithm:-
1. Initialize Variables:
2. Declare an array q of size SIZE to represent the queue.
3. Initialize two pointers front and rear to -1 to indicate the empty queue state.
4. Display Menu:
5. Show the user the following options:
a. 1: Add (Enqueue) an element to the queue.
b. 2: Delete (Dequeue) an element from the queue.
c. 3: Display the elements in the queue.
d. 4: Quit the program.
6. Loop until the user chooses to quit:
7. Ask the user for a choice of operation (ch).
8. Process the user’s choice:
9. Case 1: Add (Enqueue):
a. Check if the queue is full:
i. If rear == SIZE - 1, print "Queue overflow".
b. If not full:
i. Prompt the user to input the element to be added.
ii. If the queue is initially empty (front == -1 and rear == -1), set front = 0
to indicate the first element.
iii. Increment rear and add the new element to q[rear].
Page | 1
10. Case 2: Delete (Dequeue):
a. Check if the queue is empty:
i. If front == SIZE or front == -1, print "Queue underflow".
b. If not empty:
i. Print the element at q[front] as the deleted element.
ii. Increment front to move the front pointer to the next element.
11. Case 3: Display Queue:
a. Print all elements in the queue from q[front] to q[rear].
12. Default Case:
a. If the user enters an invalid option, print "Wrong choice".
13. Repeat until the user selects option 4 (Quit).
14. End.
Code:-
Page | 2
Output:
Page | 3
Practical Related Questions:
Page | 4
OUTPUT:-
Page | 5
2. Write a C program to implement a linear queue with operations for enqueue
(15), enqueue (48), enqueue (69), dequeue, enqueue (12), enqueue (23), dequeue,
dequeue checking if the queue is empty or full, and displaying the current queue.
Page | 6
Page | 7
OUTPUT: -
Exercise:
A Queue is an Abstract Data Type (ADT) that operates on the principle of FIFO
(First-In, First-Out). The first element added is the first to be removed.
Key Characteristics
Basic Operations:
Properties:
- FIFO Order: Elements are processed in the order they were added.
- Dynamic Size: The queue can grow or shrink as needed.
Page | 8
Applications
Queues have a wide range of applications across various domains. Here are
some key applications:
Operating Systems
- Process Scheduling: Queues manage processes in a system, allowing the
CPU to handle tasks in a fair and orderly manner, often through ready
queues and job queues.
- I/O Buffers: Queues are used to hold data from input/output devices
until the CPU is ready to process it.
Networking
- Packet Queuing: In routers and switches, packets are queued before they
are forwarded, ensuring data packets are sent in the order they are
received.
- Print Spooling: Print jobs are queued to be processed sequentially by a
printer.
Customer Service
- Call Center Management: Calls are queued until they can be answered
by an available operator, ensuring a first-come, first-served approach.
- Ticketing Systems: Customer service requests and ticket purchases are
handled in queues to maintain order.
Page | 9
Manufacturing
- Job Scheduling: In assembly lines, tasks are queued for processing to
optimize workflow and resource allocation.
- Inventory Management: Products may be queued for restocking or
shipment based on demand.
Gaming
- Player Matchmaking: Players are queued for matchmaking in
multiplayer games to ensure balanced teams.
- Event Handling: Game events (like player actions) are processed in the
order they occur using queues.
Web Development
- Request Handling: Web servers manage incoming requests using
queues, allowing for orderly processing and load balancing.
- Task Scheduling in Background Jobs: Jobs such as sending emails or
processing data are queued to be executed asynchronously.
Robotics
- Task Management: Robots can queue tasks that need to be completed,
ensuring they are handled in the correct sequence.
Telecommunications
- Message Queuing: Messages are queued in systems like SMS or
messaging apps, ensuring they are delivered in the order they were sent.
Dated signature of Teacher
Marks Obtained
Page | 10
Page | 11