Lab-05 - Linear and Circular Queue
Lab-05 - Linear and Circular Queue
Lab 05 : Queue
Introduction
This lab is based on queues and its implementation statically and dynamically.
Objectives
Objective of this lab is to get familiar with the queues and implement it in a programming
language
Tools/Software Requirement
Helping Material
Description
In computer science, a queue is a particular kind of abstract data type or collection in which the
entities in the collection are kept in order and the principal (or only) operations on the collection
are the addition of entities to the rear terminal position and removal of entities from the front
terminal position. This makes the queue a First-In-First-Out (FIFO) data structure.
Tasks:
Task 1:
You are required to implement all operations of Queue ADT using an array-based linear queue.
Task 2:
You are required to implement all operations of Queue ADT using an array-based circular queue
Task 3:
You have to implement a waiting room management system in an emergency ward of a hospital.
Your program will assign an Id number to a patient in a first come first serve basis. The lower
the id, the sooner the service will be provided to the patient.
CancelAll(): This method cancels all appointments of the patients so that the doctor can
go to lunch.
ShowAllPatient(): This method shows all ids of the waiting patients in SORTED order.
(Hint: use the sorting methods learnt in class using the appropriate data-structure for each
task) [Sorted according to their names]
Take an array of non-negative integers. Find the largest multiple of 3 that can be formed from
array elements.
For example, if the input array is {8, 1, 9}, the output should be “9 8 1”, and if the input array is
{8, 1, 7, 6, 0}, output should be “8 7 6 0”.
Hint :
1. Sort the array in non-decreasing order.
2. Take three queues. One for storing elements which on dividing by 3 gives remainder as 0.The
second queue stores digits which on dividing by 3 gives remainder as 1. The third queue stores
digits which on dividing by 3 gives remainder as 2. Call them as queue0, queue1 and queue2
3. Find the sum of all the digits.
4. Three cases arise:
……4.1 The sum of digits is divisible by 3. Dequeue all the digits from the three queues. Sort
them in non-increasing order. Output the array.
……4.2 The sum of digits produces remainder 1 when divided by 3.
Remove one item from queue1. If queue1 is empty, remove two items from queue2. If queue2
contains less than two items, the number is not possible.
……4.3 The sum of digits produces remainder 2 when divided by 3.
Remove one item from queue2. If queue2 is empty, remove two items from queue1. If queue1
contains less than two items, the number is not possible.
5. Finally empty all the queues into an auxiliary array. Sort the auxiliary array in non-increasing
order. Output the auxiliary array.
Deliverables:
Compile a single word document by filling in the solution part and submit this Word file on
LMS. The name of word document should follow this format. i.e. YourFullName(reg)_Lab#.
This lab grading policy is as follows: The lab is graded between 0 to 10 marks. The submitted
solution can get a maximum of 5 marks. At the end of each lab or in the next lab, there will be a
viva related to the tasks. The viva has a weightage of 5 marks. Insert the solution/answer in this
document. You must show the implementation of the tasks in the designing tool, along with your
complete Word document to get your work graded. You must also submit this Word document
on the LMS. In case of any problems discuss it by emailing it to [email protected].
Note: Students are required to upload the lab on LMS before deadline.