Queues TheQueueA collection of " that " container A - - PowerPoint PPT Presentation

queues thequeuea
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Queues

slide-2
SLIDE 2

TheQueueA

A

"container " that

stores

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 .

slide-3
SLIDE 3

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 → not

a

palindrome .

  • palindrome
slide-4
SLIDE 4 I

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

slide-5
SLIDE 5

Variables

: forget } pointers to

nodes

.

size

: #

elements

in the queue

.

NodeTypg has variables data

4 next

slide-6
SLIDE 6

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
slide-7
SLIDE 7

I

%④→rew_

  • v. as
' .
slide-8
SLIDE 8

Queue.ArrayImplemeutation.FI

slide-9
SLIDE 9

← 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

slide-10
SLIDE 10

Array-tmplemeutationofQuaue.FI#E

front

back

%

IeIts

=p

front

.ba#p)3dfgaeues-Tenguueuej

¥¥t¥ benguela

back

slide-11
SLIDE 11
  • 77

Longman

K

"

front

. " JackI

trwtopk.cn#nextenqueve

goes

to :

back II. front

slide-12
SLIDE 12

IT

{ degree twice

fb

¥¥t¥

  • p:ar

.€¥Et

slide-13
SLIDE 13

Variables

: array

A ← 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

slide-14
SLIDE 14

F-rid