Queue Basics
Queue Basics
A queue is a linear list of elements in which deletion can take place only at one
end, called the front, and insertions can take place only at the other end, called the rear.
The term front and rear are used in describing a linear list only when it is
implemented as a queue.
Queue is also called first-in-first-out (FIFO) lists. Since the first element in a
queue will be the first element out of the queue. In other words, the order in which
elements enters a queue is the order in which they leave.
There are main two ways to implement a queue :
1. Circular queue using array
2. Linked Structures (Pointers)
Following Figure shows that how a queue may be maintained by a circular array with
MAXSIZE = 6 (Six memory locations). Observe that queue always occupies consecutive
locations except when it occupies locations at the beginning and at the end of the array.
If the queue is viewed as a circular array, this means that it still occupies consecutive
locations. Also, as indicated by Fig(k), the queue will be empty only when Count = 0 or
(Front = Rear but not null) and an element is deleted. For this reason, -1 (null) is
assigned to Front and Rear.
This
is
also
known
as
"pop_element(Off)",
"get_maximum_element"
or
values
to
be
higher
priority,
so
this
may
also
be
known
as
be
specified
"delete_element"
as
functions,
separate
which
"peek_at_highest_priority_element"
can
be
combined
to
and
produce
"pull_highest_priority_element".
In addition, peek (in this context often called find-max or find-min), which
returns the highestpriority element but does not modify the queue, is very frequently
implemented, and nearly always executes in O(1) time. This operation and its O(1)
performance is crucial to many applications of priority queues.
More advanced implementations may support more complicated operations,
such as pull_lowest_priority_element, inspecting the first few highest- or lowestpriority elements, clearing the queue, clearing subsets of the queue, performing a batch
insert, merging two or more queues into one, incrementing priority of any element, etc.
CIRCULAR QUEUE:
In a standard queue data structure re-buffering problem occurs for each dequeue
operation. To solve this problem by joining the front and rear ends of a queue to make
the queue as a circular queue Circular queue is a linear data structure. It follows FIFO
principle.
In
a
circular queue the last node is connected back to the first node to make
circle.
Circular
Elements
are added at the rear end and the elements are deleted at front
end of the
Both
It
queue.
the front and the rear pointers points to the beginning of the array.
is also called as Ring buffer.
Items