3. Queue is an ordered group of homogeneous
items of elements.
A queue has two ends - front end & rear
end.
Insertion can take place at rear end &
deletion can take place at front end.
4. Queue is also known as First In First
Out(FIFO) data structure.
Insertion & Deletion operations are known
as Enqueue & Dequeue respectively.
Front Rear
5. The following operations are performed on
queue:-
1. CreateQueue(q)- To create q as an empty queue.
2. Enqueue(q, i)- To insert an element i in the
queue.
3. Dequeue(q)- To access & remove an element of
the queue.
4. Peek(q)- To access the first element of the
queue without removing it.
5. IsFull(q)- to check whether the queue is full.
6. IsEmpty(q)- To check whether the queue is
empty.
6. Queue can be represented in memory using linear
array or linear linked list.
A queue represented using a linked list is called a
linked queue.
The overflow condition for array implementation is
front is equal to zero & rear is equal to (size of
array)-1.
The underflow condition for array implementation is
front is equal to -1.
8. We define two datatypes- node &
queue.
The datatype queue, a structure
whose first element front holds the
address of first element of queue &
second element rear holds the
address of last element of the
queue.
13. int Dequeue(queue *pq)
{
int temp;
node *ptr;
temp=(pq->front)->info;
ptr=pq->front;
if(pq->front==pq->rear)
pq->front=pq->rear=NULL;
else
pq->front=(pq->front)->next;
free(ptr);
return temp;
}
14. Queue is used to access files from a
disk system.
In a multiprogramming environment,
queue is used for CPU scheduling or
job scheduling of operating system.
In ticket reservation system, queue
can be used for issuing tickets to the
customers.