Queue Based Data Structure
-
Upload
mbanzabugabo-jean-baptiste -
Category
Documents
-
view
217 -
download
0
Transcript of Queue Based Data Structure
-
7/25/2019 Queue Based Data Structure
1/4
QUEUE BASED DATA STRUCTURE
It is a linear data structure represent a container of objects that are inserted and removed according to the first-in-first-
out (FIFO)principle. That is, elements can be removed at any time, but only the element that has been in the queue the
longest can be removed at any time; that is random access of any specific item is not allowed. Queue elements may be
inserted at the back called the !"#! end$ and removed from the front end called %!&'T end$.
(!")"'T#TI&' &% Q*"*"
%ront !ear
Insertion+eletio
n
-
7/25/2019 Queue Based Data Structure
2/4
Algorithm 8.! E"QUEUE-Let Qbe a Queue consisting of N elements.
FRONTandREARare pointers to the front and rear elements of a queue. This
algorithm inserts ITEM at the rear end of the queue.
)tep - /heck for overflow0
If !"#! 1 ' Then
+isplay 2&verflow34
"5it
"ndIf0
)tep 6- /heck for empty queue0
If %!&'T 1 7 Then
%!&'T 1 8 and !"#! 1 8 Insert IT"9 as first element of the queue0
"lse
Increment !"#! pointer0
!"#! 1 !"#! :
"ndIf0
-
7/25/2019 Queue Based Data Structure
3/4
)tep - Q!"#!0 1 IT"9
)tep
-
7/25/2019 Queue Based Data Structure
4/4
"lse
Increment %!&'T pointer0
%!&'T 1 %!&'T :
"ndIf0
)tep