Queues
Queues TheQueueA collection of " that " container A - - PowerPoint PPT Presentation
Queues TheQueueA collection of " that " container A - - PowerPoint PPT Presentation
Queues TheQueueA collection of " that " container A stores a insertion and removal in with items " first - in - first - out " order . push pop 49 Stack : -1% Queue : & : : : degueae engaeae Basic
TheQueueA
A
"container " thatstores
a
collection of
items
with
insertion and removal
in
" first - in - first - out
"
- rder .
push
pop
49
Stack : -1% Queue :
- &
: : :
degueae
④
engaeae
Basic operations :
enqueue
:add
an item
to the
back of
the list
degueue :
remove
an item from the
front
- f the
list .
Example : Palindrome Checking
.aba
aab
✓
×
In
an array
: IT
i
i
j si
with
a
stack
and
queue
:
- I. read symbols , storing
each
in
a
stack
and
a
queue
.{
.
%:*:
em
+ deqve
an
element from the
queue
.z
.if different → nota
palindrome .
- palindrome
Queuejhinkedhisttmplemewtatim-ba.ie ,
Enquire
: add
a new
node to the
Degueue
: remove the
' front' element
front
→FIFTEEN
backD-
°Engue
fit
f-t.tt#-oFHYeTy.-HdTd*-ij
Dif ¥⇒¥ht4→④
b.htretap
Variables
: forget } pointers to
nodes
.size
: #elements
in the queue
.NodeTypg has variables data
4 next
engueuelx){
n←newnodecoutamg£
dd it to the
list
back←back⇒nT
}
size
= street In
front
' Drops . . .- i. ID1-1TI
back
D-fdegue.ae
C){ ×✓
temp a- front
③
← front⇒data
- • front
e- front-onext
- delete
temp
- sites
site
- I
}
- return ral
I
%④→rew_
- v. as
Queue.ArrayImplemeutation.FI
← empty queue
enaoueue a
FP9R
Ip
queue
is :
IT
c.die
engweeeebf.ph#enqueoeep-j
Any
KID
enqueue
a f¥¥
rtft
1-1
degueeb.ae
.
engulf
degueue I
engage#
1¥11
f- 4
* r
degree ft
tr
engined by
degree £-1
H f 't
ft Pr
Array-tmplemeutationofQuaue.FI#E
front
back
%
IeIts
=p
front
.ba#p)3dfgaeues-Tenguueuej
¥¥t¥ benguela
back
- 77
Longman
K
"
front
. " JackI
trwtopk.cn#nextenqueve
goes
to :
back II. front
IT
{ degree twice
fb
¥¥t¥
- p:ar
.€¥Et
Variables
: arrayA ← array
- f
size capacity
front ←
- back ← 0
size
← o
capacity
← ?
- enqoueue (e){
A [ back % capacity
I*X
Site t= 1
A [ back] ← ×
back = backthe
site
= size t I- back
e (back t 1)
% capacity
.}
degueve.DE
temp ← Affront] front
← front
t 1) % capacity site
← site
- I
}
return temp
F-rid