32211112 stack and queue

Download 32211112 Stack and Queue

Post on 22-Jul-2015

164 views

Category:

Documents

0 download

Embed Size (px)

TRANSCRIPT

CHNG 6 STACK v QUEUE

MC TIUSau chng ny bn c th: Gii thch cu trc v cch lm vic ca stack Bit s dng cu trc stack gii mt s bi ton Gii thch cu trc v cch lm vic ca queue Bit s dng cu trc queue gii mt s bi ton

2

n tp. 6.1- Gii thiu 6.2- Chng-Stack. 6.3- Minh ha v s dng stack 6.4- Hng i - Queue 6.5- S dng queue Tm tt.

NI DUNG

3

n tp Tm kim l qua trnh da trn mt cht thng tin (kho tm kim) c xc nh v tr c thng tin cn tm trong mt nhm tr. Hai gii thut tm kim: Tm kim tuyn tnh v tm kim nh phn. Tm kim tun t c th dng cho mt nhm tr bt k. Tm kim nh phn ch dng cho nhm tr c th t.

4

Sp xp l qa trnh ti b tr cc phn t trong mt nhm tr theo mt c ch so snh no . C ch selection sort: tm 1 tr nh nht trong nhm tr cn phi sp xp a v u nhm ny. C ch Bubble sort: Hon chuyn dn cc tr nh di ln pha trn. C ch Insertion sort: Ly 1 tr pha sau chn vo v tr thch hp trong nhm tr c th t pha trc5

n tp

6.1- Gii thiu Mng thng thng cho php truy xut bt k phn t no Khng hn ch truy cp. C nhng danh sch hn ch cch truy cp. Chng(stack) a ch cho php truy cp 1 chiu Hng i khi mua v l mt danh sch hn ch cch truy cp.

6

Gii thiu Chng (stack)Khi y

C ch: Last In First Out LIFO

Thm vo

Ly ra7

Gii thiu Queue- Hng i

8

Gii thiu Queue- Hng iHng y

C ch: Vo trc ra trc First In First Out- FIFO9

6.2- Stack M t stack Khi to 1 stack Kim tra stack trng Kim tra stack y Thm 1 phn t vo stack Ly phn t nh stack ra

10

6.2.1- M t Stack bng mngStack cha mt nhm phn t kiu no (T) mng Mng chim dng b nh bao nhiu? 2 7 9 5 Ti 1 thi im, v tr trn cng l v tr no? T* ar 1000int maxSize 32

31 2 ... 1000 5 3 ... 0

K thut template cho php nh ngha 1 tn gi cho 1 kiu d liu tru tng. Khi s dng s n nh kiu c th

int top 3

template struct STACK { int maxSize; T* ar; int top; };

B nh11

6.2.2- Tc v khi to (Init) 1 stack vi MaxSize phn ttemplate void Init (STACK & St, int MaxSize=32) { if (MaxSize