The document discusses different types of queues and their implementations. It begins by defining a queue as a first-in first-out (FIFO) data structure where elements are inserted at the rear and deleted from the front. It then covers linear and circular queue implementations using arrays, including operations like insertion, deletion, checking for empty/full, and traversal. Priority queues are also introduced, which process elements based on assigned priorities. The key types and operations of queues as an abstract data type (ADT) are summarized.
Queues
a. Concept and Definition
b. Queue as an ADT
c. Implementation of Insert and Delete operation of:
• Linear Queue
• Circular Queue
For More:
https://github.com/ashim888/dataStructureAndAlgorithm
http://www.ashimlamichhane.com.np/
Queue is a collection whose elements are added at one end and removed from the other end
What is a Queue
Conceptual View of a Queue
Uses of Queues in Computing
Operations on a Queue
Implementation of a Queue
Applications
Downloadable Resources
a. Concept and Definition✓
b. Inserting and Deleting nodes ✓
c. Linked implementation of a stack (PUSH/POP) ✓
d. Linked implementation of a queue (Insert/Remove) ✓
e. Circular List
• Stack as a circular list (PUSH/POP) ✓
• Queue as a circular list (Insert/Remove) ✓
f. Doubly Linked List (Insert/Remove) ✓
For more course related material:
https://github.com/ashim888/dataStructureAndAlgorithm/
Personal blog
www.ashimlamichhane.com.np
Queues
a. Concept and Definition
b. Queue as an ADT
c. Implementation of Insert and Delete operation of:
• Linear Queue
• Circular Queue
For More:
https://github.com/ashim888/dataStructureAndAlgorithm
http://www.ashimlamichhane.com.np/
Queue is a collection whose elements are added at one end and removed from the other end
What is a Queue
Conceptual View of a Queue
Uses of Queues in Computing
Operations on a Queue
Implementation of a Queue
Applications
Downloadable Resources
a. Concept and Definition✓
b. Inserting and Deleting nodes ✓
c. Linked implementation of a stack (PUSH/POP) ✓
d. Linked implementation of a queue (Insert/Remove) ✓
e. Circular List
• Stack as a circular list (PUSH/POP) ✓
• Queue as a circular list (Insert/Remove) ✓
f. Doubly Linked List (Insert/Remove) ✓
For more course related material:
https://github.com/ashim888/dataStructureAndAlgorithm/
Personal blog
www.ashimlamichhane.com.np
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
Infix to Postfix Conversion Using StackSoumen Santra
Infix to Postfix Conversion Using Stack is one of the most significant example of application of Stack which is an ADT (Abstract Data Type) based on LIFO concept.
An ordered collection of items from which items may be deleted from one end called the front and into which items may be inserted from other end called rear is known as Queue.
It is a linear data structure.
It is called the First In First Out (FIFO) list. Since in queue, the first element will be the first element out.
Data Structure- Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −
PUSH, POP, PEEP
Queue is an abstract data structure, somewhat similar to Stacks. Unlike stacks, a queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue). Queue follows First-In-First-Out methodology, i.e., the data item stored first will be accessed first.
Infix to Postfix Conversion Using StackSoumen Santra
Infix to Postfix Conversion Using Stack is one of the most significant example of application of Stack which is an ADT (Abstract Data Type) based on LIFO concept.
An ordered collection of items from which items may be deleted from one end called the front and into which items may be inserted from other end called rear is known as Queue.
It is a linear data structure.
It is called the First In First Out (FIFO) list. Since in queue, the first element will be the first element out.
Data Structure- Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −
PUSH, POP, PEEP
LINEAR QUEUE with Diagram and C implementation.
Operations of LINEAR QUEUE
Drawback of LINEAR QUEUE
CIRCULAR QUEUE with Diagram and C implementation
Operations of CIRCULAR QUEUE
PRIORITY QUEUE with Diagram and C implementation
Operations of PRIORITY QUEUE
CASE STUDIES
EXAMPLES
CFD Simulation of By-pass Flow in a HRSG module by R&R Consult.pptxR&R Consult
CFD analysis is incredibly effective at solving mysteries and improving the performance of complex systems!
Here's a great example: At a large natural gas-fired power plant, where they use waste heat to generate steam and energy, they were puzzled that their boiler wasn't producing as much steam as expected.
R&R and Tetra Engineering Group Inc. were asked to solve the issue with reduced steam production.
An inspection had shown that a significant amount of hot flue gas was bypassing the boiler tubes, where the heat was supposed to be transferred.
R&R Consult conducted a CFD analysis, which revealed that 6.3% of the flue gas was bypassing the boiler tubes without transferring heat. The analysis also showed that the flue gas was instead being directed along the sides of the boiler and between the modules that were supposed to capture the heat. This was the cause of the reduced performance.
Based on our results, Tetra Engineering installed covering plates to reduce the bypass flow. This improved the boiler's performance and increased electricity production.
It is always satisfying when we can help solve complex challenges like this. Do your systems also need a check-up or optimization? Give us a call!
Work done in cooperation with James Malloy and David Moelling from Tetra Engineering.
More examples of our work https://www.r-r-consult.dk/en/cases-en/
Courier management system project report.pdfKamal Acharya
It is now-a-days very important for the people to send or receive articles like imported furniture, electronic items, gifts, business goods and the like. People depend vastly on different transport systems which mostly use the manual way of receiving and delivering the articles. There is no way to track the articles till they are received and there is no way to let the customer know what happened in transit, once he booked some articles. In such a situation, we need a system which completely computerizes the cargo activities including time to time tracking of the articles sent. This need is fulfilled by Courier Management System software which is online software for the cargo management people that enables them to receive the goods from a source and send them to a required destination and track their status from time to time.
Vaccine management system project report documentation..pdfKamal Acharya
The Division of Vaccine and Immunization is facing increasing difficulty monitoring vaccines and other commodities distribution once they have been distributed from the national stores. With the introduction of new vaccines, more challenges have been anticipated with this additions posing serious threat to the already over strained vaccine supply chain system in Kenya.
TECHNICAL TRAINING MANUAL GENERAL FAMILIARIZATION COURSEDuvanRamosGarzon1
AIRCRAFT GENERAL
The Single Aisle is the most advanced family aircraft in service today, with fly-by-wire flight controls.
The A318, A319, A320 and A321 are twin-engine subsonic medium range aircraft.
The family offers a choice of engines
Final project report on grocery store management system..pdfKamal Acharya
In today’s fast-changing business environment, it’s extremely important to be able to respond to client needs in the most effective and timely manner. If your customers wish to see your business online and have instant access to your products or services.
Online Grocery Store is an e-commerce website, which retails various grocery products. This project allows viewing various products available enables registered users to purchase desired products instantly using Paytm, UPI payment processor (Instant Pay) and also can place order by using Cash on Delivery (Pay Later) option. This project provides an easy access to Administrators and Managers to view orders placed using Pay Later and Instant Pay options.
In order to develop an e-commerce website, a number of Technologies must be studied and understood. These include multi-tiered architecture, server and client-side scripting techniques, implementation technologies, programming language (such as PHP, HTML, CSS, JavaScript) and MySQL relational databases. This is a project with the objective to develop a basic website where a consumer is provided with a shopping cart website and also to know about the technologies used to develop such a website.
This document will discuss each of the underlying technologies to create and implement an e- commerce website.
Event Management System Vb Net Project Report.pdfKamal Acharya
In present era, the scopes of information technology growing with a very fast .We do not see any are untouched from this industry. The scope of information technology has become wider includes: Business and industry. Household Business, Communication, Education, Entertainment, Science, Medicine, Engineering, Distance Learning, Weather Forecasting. Carrier Searching and so on.
My project named “Event Management System” is software that store and maintained all events coordinated in college. It also helpful to print related reports. My project will help to record the events coordinated by faculties with their Name, Event subject, date & details in an efficient & effective ways.
In my system we have to make a system by which a user can record all events coordinated by a particular faculty. In our proposed system some more featured are added which differs it from the existing system such as security.
Saudi Arabia stands as a titan in the global energy landscape, renowned for its abundant oil and gas resources. It's the largest exporter of petroleum and holds some of the world's most significant reserves. Let's delve into the top 10 oil and gas projects shaping Saudi Arabia's energy future in 2024.
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
2. Unit – 4
Contents Hours Marks
a. Concept and definition
b. Queue as ADT
c. Implementation of Insert and Delete Operations Of:
• Linear Queue
• Circular Queue
d. Concept of Priority Queue
4 5
2
3. 3
What is a Queue?
• A Queue is an ordered collection of items in which items are inserted at one
end (called the rear of the queue) and items are deleted at the other end (the
front of the queue).
• Since the first element inserted into the queue is the first element to be
removed, a queue is sometimes called a FIFO (first-in first-out) list as
opposed to the stack, which is a LIFO (last-in first-out).
Items [ MAX-1]
…
Items [4]
Items[3] D rear
Items[2] C
Items [1] B
Items [0] A front
4. Operations on Queue
• Some of the typical operations performed on queues are:
MakeEmpty(q): To make q as an empty queue
Enqueue(q, x): To insert an item x at the rear of the queue, this is also
called by names add, insert.
Dequeue(q): To delete an item from the front of the queue q. This is also
known as delete, remove.
IsFull(q): To check whether the queue q is full.
IsEmpty(q): To check whether the queue q is empty
Traverse (q): To read entire queue that is display the content of the queue.
4
5. Insertion of data into Queue
Insert( 3)
front =0
increment rear
i.e. rear = rear + 1
rear =0
front =0
rear = -1
front 3
Insert( 5)
front =0
rear =1 5
3
5
6. Insert( 10)
front =0
rear =2
5
3
10
Insertion of data into Queue
Insert( 8) rear = 3
3
5
10
8
front = 0
6
7. Deletion of data from the queue
rear = 3
3
5
10
8
front = 0
Delete( )
rear = 3
5
10
8
front = 1
increment front
i.e. front = front + 1
7
8. Delete( )
rear = 3
10
8
front = 2
Deletion of data from the queue
increment front
i.e. front = front + 1
8
9. Applications of Queue
• The queue is very useful in the various fields of computer science.
The applications can be listed as below:
Access to shared resources: with in computer system there may be queues
of tasks waiting for the printer, for access to disk storage, or even in a time-
sharing system, for use of the CPU.
Task scheduling in operating system
Queue can be used as an auxiliary data structure for implementing various
algorithms.
9
10. The Queue as a ADT
• A queue q of type T is a finite sequence of elements with the
operations.
MakeEmpty(q): To make q as an empty queue
IsEmpty(q): To check whether the queue q is empty. Return true if q is empty,
return false otherwise.
IsFull(q): To check whether the queue q is full. Return true in q is full, return
false otherwise.
Enqueue(q, x): To insert an item x at the rear of the queue, if and only if q is not
full.
Dequeue(q): To delete an item from the front of the queue q. if and only if q is
not empty.
Traverse (q): To read entire queue that is display the content of the queue.
10
11. Implementation of Queue
• Queue can be implemented in two ways:
1. Array Implementation of queue(or static implementation)
2. Linked list implementation of queue (or dynamic)
• Array (static) implementation of a queue:
• It implements a queue using a one dimensional array to store the data.
• Two integer variables front and rear are used to indicate front and rear index of the
queue items.
• Further array implementation may be linear or circular.
11
12. Linear Array implementation
• This implementation uses a linear array with two indices rear and front that are
always increasing.
• Linear array implementation is also called linear queue.
#define MAX 10
struct queue
{
int items[MAX]; //Declaring an array to store items
int rear; // rear of queue
int front // front of queue
};
struct queue q;
• Initialization of front and rear front = 0 and rear = -1 12
13. Creating Empty queue
• The value of rear =-1 indicates the empty queue in C
implementation.
• /*Function to create an empty queue*/
void create_empty_queue(struct queue *q)
{
q->rear =-1;
q->front =0;
}
13
14. Queue Empty or Underflow
• This is the situation when the queue contains no element.
• At this point, the queue satisfies the condition rear < front .
• The following function return 1 if the queue is empty, 0 otherwise.
• int isempty(struct queue *q)
{
if(q->rear < q->front)
return 1;
else
return 0;
}
14
15. Queue Full or Overflow
• This is the situation when the queue becomes full, and no more elements
can be inserted into the queue.
• At this point the queue rear is present at the highest location (MAXSIZE- 1) of
the queue.
• The following function returns true (1) if queue is full false (0) otherwise.
• int isfull(struct queue *q)
{
if(q->rear==MAX-1)
return 1;
else
return 0;
}
15
16. Insert operation on queue
• Let queue[MAX] be an array to implement the queue.
• The variables rear and front denotes the rear and front of the queue.
• Insert operation adds one element 'item' to the queue.
• Algorithm for INSERT operation:
1. [Check for queue overflow?]
if rear=MAXSIZE-1 then
print “queue Overflow” and Exit
else
Set rear = rear+1 [Increase rear by 1]
Set queue[rear]:= item [Inserts item in new top position]
2. Exit
16
17. The function for Insert Operation
Void insert ( struct queue *q, int newitem)
{
if(IsFull(q))
{
printf(“queue is full”);
exit(1);
}
else
{
q->rear++;
q->items[q->rear]=newitem;
}
} 17
18. Delete operation
• This operation removes an item from the queue at front end and assigns it
to a variable item
• Algorithm:
1.[Check for the queue Underflow]
If rear < front then
Print “queue Underflow” and Exit
else [Remove the front element]
Set item=queue [front]
Set front=front + 1 [Increment front by 1]
Return the deleted item from the queue
2. Exit
18
19. The C function for Delete operation
void del(struct queue *q)
{
if(isempty(q))
printf("nn queue Underflow: Empty queue!!!");
else
printf("nthe deleted item is %d:t", q->items[q->front++]);
/*deletes an element pointed by front and increments front by 1 */
}
19
20. The display Function
void display( struct queue *q)
{
int i;
if(q->rear < q->front)
{
printf("Queue is emptyn");
}
else
{
For(i=q->front; i<=q->rear ; i ++)
printf("%dt", q->item[i]);
}
20
21. Problems with Linear queue implementation
• Both rear and front indices are increased but never decreased.
• As items are removed from the queue, the storage space at the beginning of
the array is discarded and never used again.
• Wastage of the space is the main problem with linear queue which is illustrated
by the following example.
• This queue is considered full, even though the space at beginning is vacant.
• One solution to this problem is to modify the delete operation so that when an
element is deleted, the entire queue is shifted to the beginning of the array.
That is, delete always at 0th location.
21
22. Modification of Delete Operations
void delete_item ( struct queue *q)
{ int i;
if(q->rear == -1)
{ printf("Queue is emptyn");
exit(1);
}
else
{
printf("n deleted item is %d", q->items [0]);
For(i=q->front; i<q->rear ; i ++)
q->item[i]= q->items[i+1];
q-> rear --;
}
} 22
23. Circular Queue
• A circular queue is one in which the insertion of a new element is
done at very first location of the queue if the last location of the queue
is full, as long as that first cell is empty.
• A circular queue overcomes the problem of unutilized space
in linear queue implementation as array.
• While implementing circular queue, we can use two approaches
using global variable count to keep track of every insertion
and deletion operation
Sacrificing one cell vacant
10 5 6 7 8 10
0 1 2 3 4 5
23
24. Sacrificing One Cell Vacant
• In array implementation of circular queue, the incrementing operation is
used for ease:
rear = (rear +1) % MAX
front = (front + 1) % MAX
• Both front and rear are initialized to MAX -1.
i.e. rear = MAX -1 and front = MAX - 1
• This initialization has empty situation: front == rear
• When we insert elements in the queue, the overflow situation is also same:
front == rear.
• To resolve this conflict, we sacrifice one cell of the array as a vacant thus to
insert n elements in a circular queue we need an array of size n + 1.
• That is, we can insert one less than the size of the array in circular queue.
• This problem can also be solved by using a global counter variable.
24
25. Declaration of a Circular Queue
• The declaration of circular queue is same as that of linear queue.
# define MAX 10 /* size of the circular queue items*/
struct cqueue
{
int front;
int rear;
int items[MAX];
};
struct cqueue cq;
• Initialization of rear and front
cq.rear = MAX -1; cq.front = MAX - 1
25
26. Operations of a circular queue
• The operations on a circular queue are also same as that
of linear queue.
1. makeEmpty queue
void makeEmpty(struct cqueue *q)
{
q->rear = MAX-1;
q->front = MAX-1;
}
26
27. 2. Overflow and Underflow Tests
int IsEmpty( struct cqueue *q)
{
if(q->rear == q->front)
return 1;
else
return 0;
}
int IsFull(struct cqueue *q)
{
if(q->front==(q->rear+1)%MAX)
return 1;
else
return 0;
}
• IsFull Test • IsEmpty Test
27
28. 3. Inserting an element in a circular queue
• Assume that rear and front are initially set to MAX-1.
• Cqueue is array to hold items and item is new element to be
added.
• Algorithm:
1. if (front == (rear+1)%MAX)
print Queue is full and exit
2. else
rear = (rear+1)%MAX; [increment rear by 1]
cqueue[rear] = item;
3. end
28
29. 4. Deletion from Circular Queue
• Assume that rear and front are initially set to MAX-1.
• Cqueue is array that holds items.
• Algorithm
1. if (rear == front) [checking empty condition]
print Queue is empty
exit
2. Else
front=(front+1)%MAX; [increment front by 1]
item=cqueue[front];
return item;
3. end.
29
30. The Enqueue function:
void Enqueue(struct cqueue*q, int newitem)
{
if(IsFull(q))
{
printf(“queue is full”);
exit(1);
}
else
{
q->rear=(q->rear+1)%MAX;
q->items[q->rear]=newitem;
}
}
30
31. The Dequeue function
int Dequeue(struct cqueue *q)
{
if(IsEmpty(q))
{
printf(“queue is Empty”);
exit(1);
}
else
{
q->front = (q->front+1)%MAX;
return(q->items[q->front]);
}
}
31
32. Display Function
32
void display(struct cqueue *q)
{
int i;
if(q->rear==q->front)
printf("Queue is emptyn");
else
{
printf("Items of queue are:n");
for(i=(q->front+1)%MAX;i!=q->rear;i=(i+1)% MAX
{
printf("%dt",q->item[i]);
}
printf("%dt",q->item[q->rear]);
}
}
33. Circular Queue Using Global Counter
• To avoid loss of one array cell , a global integer variable "count" is used.
• Circular queue declaration is same as before:
#define MAX 10
struct cqueue
{
int item[MAX];
int rear;
int front;
};
struct cqueue cq;
• Global counter variable: int count = 0;
• Initialization:
int cq.front = MAX-1;
int cq.rear = MAX-1;
33
34. Insert Function
void insert(struct cqueue *q)
{
int d;
if(count==MAX)
printf("Queue is fulln");
else
{
q->rear=(q->rear+1)%MAX;
printf ("Enter data to be insertedn");
scanf("%d", &d);
q->item[q->rear] = d;
count++;
}
}
34
35. Delete Function
void deletion (struct cqueue *q)
{
if(count==0)
printf("Queue is emptyn");
else
{
q->front = (q->front+1)%MAX;
printf (" Deleted Item is t");
printf("%d", q->item[q->front]);
count--;
}
}
35
36. void display(struct cqueue *q)
{
int i;
if(q->rear == q->front)
printf("Queue is emptyn");
else
{
printf("Items of queue are:n");
for(i=(q->front+1)%MAX; i!=q->rear; i=(i +1)%MAX)
{
printf("%dt",q->item[i]);
}
printf("%dt",q->item[q->rear]);
}
}
Display Function
36
37. Priority Queue
• A priority queue is a collection of elements such that
each element has been assigned a priority and the order
in which elements are deleted according to the following
rules:
An element of higher priority is processed before any element of lower
priority.
If two elements has same priority then they are processed according to
the order in which they were added to the queue.
37
38. Application of Priority Queue
• In a time-sharing computer system, a large number of tasks may be
waiting for the CPU, some of these tasks have higher priority than
others. The set of tasks waiting for the CPU forms a priority queue.
• The jobs which have higher priority are processed first.
• If the priority of two jobs is same this jobs are processed according to
their position in queue.
• A shorter job is given higher priority over the longer one.
38
39. Types of priority queues
• Ascending priority queue(min priority queue):
An ascending priority queue is a collection of items into which items
can be inserted arbitrarily but from which only the smallest item can
be removed.
• Descending priority queue(max priority queue):
An descending priority queue is a collection of items into which items
can be inserted arbitrarily but from which only the largest item can be
removed.
39
40. Priority QUEUE Operations
• Insertion : The insertion in Priority queues is the same as in non-priority
queues.
• Deletion : Deletion requires a search for the element of highest
priority and deletes the element with highest priority.
• The following methods can be used for deletion/removal from a given
Priority Queue:
An empty indicator replaces deleted elements.
After each deletion elements can be moved up in the array
decrementing the rear.
The array in the queue can be maintained as an ordered circular
array
40
41. The priority queue ADT
A ascending priority queue of elements of type T is a finite sequence of
elements of T together with the operations:
• MakeEmpty(p): Create an empty priority queue p
• Empty(p): Determine if the priority queue p is empty or not
• Insert(p,x): Add element x on the priority queue p
• DeleteMin(p): If the priority queue p is not empty, remove the
minimum element of the queque and return it.
• FindMin(p): Retrieve the minimum element of the priority queue p.
41
42. Array implementation of priority queue
Unordered array implementation
• To insert an item, insert it at the rear end of the queue.
• To delete an item, find the position of the minimum
element and
Either mark it as deleted (lazy deletion) or
shift all elements past the deleted element by on position
and then decrement rear.
42
43. 55 39 77 44
f r
43
Illustration of unordered array implementation
Insert (65)
55 39 77 44 65
f r
deleteMin( )
55 -1 77 44 65
f r
Deleted
55 -1 77 -1 65
f r
deleteMin( )
44. Priority Queue Declaration
44
• Queue data type of Priority Queue is the same as the Non-
priority Queue.
#define MAX 10 /* size of the queue items*/
struct pqueue
{
int items[MAX];
int front;
int rear;
};
45. Insert Function
45
void insert( struct pqueue *q)
{
int x;
if(q->rear==MAX-1)
printf("Queue is fulln");
else
{
printf ("Enter data to be insertedn");
scanf("%d",&d);
q->rear++;
q->items[q->rear]=x;
}
}
47. 47
void display(pq *q)
{
int i;
if(q->rear < q->front)
printf("Queue is emptyn");
else
{
printf("Items of queue are:n");
for(i=q->front; i<=q->rear;i++)
{
printf("%dt", q->item[i]);
}
}
}
Display Function
48. Ordered array implementation
48
• In this implementation, the front is the position of the smallest
element and the rear is the position of the largest element.
• To insert an element, locate the proper position of the new
element and shift succeeding elements by one position.
• To delete the minimum element, delete element at the front
position and shift all elements one position towards front and
decrement rear.
50. Insert Function
50
void insert(struct pqueue *q)
{
int x,i,j;
if(q->rear == MAX -1)
printf("n Queue is fulln");
else
{
printf ("nEnter data to be insertedt");
scanf("%d",&x);
for(i=q->front;i<=q->rear;i++)
{
if(x < q->item[i])
{
break;
}
}
for(j=q->rear;j>=i;j--)
q->item[j+1]= q->item[j];
q->rear = q->rear+1;
q->item[i] = x;
}
}
51. Delete Function
51
void delet(struct pqueue *q)
{
int i, x;
if(q->rear < q->front)
{
printf("nQueue is emptyn");
}
else
{ x=q->item[q->front];
for(i=q->front;i<q->rear;i++)
{
q->item[i]=q->item[i+1];
}
q->rear--;
printf("n Deleted item is %d", x);
}
}
52. Homework #5
1. How can you use queue as ADT?
2. Write a Menu program to demonstrate he simulation of queue operations in array
implementation.
3. Write a C function to display all items in the circular queue. Write assumptions
you need.
4. Write circular queue operations in array implementation.
5. What is a priority queue? How is it best implemented?
6. Define queue as an ADT. Write a program for basic operations in Linear queues
in array implementation.