Title: ?????????????????? Queue
1?????????????????? Queue
Data Structure
Department of Computer Science
2??????????????????????????? Queue
- ??????????????? Queue ????????????????????????????
?????????????????????????? ?? ?????????????????
Queue ???????????????????????????? queue
?????????????????? ???????? ??????????????????????
??? FIFO (first-in-first-out)
Data Structure
Department of Computer Science
3Operation ??? Queue
- 1. Insert ???? operation ???????????????????????
Queue - 2. Delete ???? operation ????????????????????
Queue - ????? Insert ??? Delete ?????????? 2 ?????? ???
- 1. ??????????????????????????????????????????
Queue (Front) - 2. ????????????????????????????????????????
Queue (Rear)
Data Structure
Department of Computer Science
4??????????????????? Operation Insert ??? Delete
(???????????????? Queue ?? 5 ?????)
5Implementation Queue
- ??? Implement Queue ????? 2???????1. Array
Implementation2. Linked List Implementation
Data Structure
Department of Computer Science
6Insert Algorithm
- Array Implementation Insert Algorithm
- 1. ?????????? Queue ???? ? ( Rear N)
- - ??? Queue ???? ????????????????? "Queue
Overflow" ??????????? - - ??? Queue ??????? ?????????????? 2 ??? 3
- 2. ?????????????? Rear ??? 1
- 3. ????????????? Queue ?????????????????? Rear
Data Structure
Department of Computer Science
7Flowchat
Data Structure
Department of Computer Science
8?????????????????????? Queue ??? Integer
- Program Pascal
- Procedure Insert ( X ) BeginIf RearN Then
Writeln ( " Queue Overflow " ) ElseBeginRear
Rear 1 Queue Rear X EndEnd
Data Structure
Department of Computer Science
9?????????????????????? Queue ??? Integer
- Program C,C
- Insert ( int X )if (Rear N) printf ( "
Queue Overflow " )elseRear Rear 1
Queue Rear X
Data Structure
Department of Computer Science
10Delete Algorithm
- Array Implementation Delete Algorithm
- 1. ?????????? Queue ???? ? (????????????????
Front Rear) - - ??? Queue ???? ????????????????? "Queue
Empty" ??????????? - - ??? Queue ??????????? ?????????????? 2 ??? 3
- 2. ????????????????? Front
- 3. ??????????????????????? Front ?????? Queue
Data Structure
Department of Computer Science
11Flowchat
Data Structure
Department of Computer Science
12?????????????????????? Queue ??? Integer
- Program Pascal
- Procedure Delete(var X inteer ) BeginIf
Front Rear Then Writeln ( " Queue Empty " )
ElseBeginFront Front 1 X QueueFront
EndEnd
Data Structure
Department of Computer Science
13?????????????????????? Queue ??? Integer
- Program C,C
- Delete ( )if (Front Rear) printf ( "
Queue Empty " )elseFront Front 1 X
Queue Front
Data Structure
Department of Computer Science
14Circular Queue (????????)
15Circular Queue (????????)
- ???????????????????????????????
- ??????????????????????????????????????????
???????????????????? - ????????????????????? ?????????????????????
- ??????????????????????????? (Full Queue)
?????????????????????? - ???????????????? ?????????? F ???????????????????
?????? ???????????????? - ??????????????????????????????????????????????????
?????????????? - (Empty Queue) ???????????????????????????????? F
??? R ???????????? - ?????????????????????? ???????????????????????????
????????????????????? - ????? F ?????? ???????????????????????????????????
????? F ???????????? - ??????????? (????????????) ???????????????????????
?????????
16Circular Queue (????????)
- ??????????????????????? ?????????????????????????
??????????????? - ???????????? ?????????????????????????????????????
????????????????? - ??????????????????????????? ???
???????????????????? (Front) - ??????????????????????? (Rear)
??????????????????????????? - ???????? ???????? (Circular Queue)
17Circular Queue (????????)
- ??????????
- ??????????????????????????????????????????????????
?????????????????? 6 ?????????????
??????????????? 0-4 ?????? ??????????????????
??????????????????????????????????????????? ????
???????????????????????????????? 100 ????
??????????????????????????????????????? 100
?????????? ??????????????????????? ???????????
?????? (Delete) ?????????????????????????????????
90 ???? ????????????????????? 7 ??
???????????????? ???????? ??????????????????? 3
?? ????????? 100 ?? ??????????????????????????????
????? 90 ???? ?????? ?????????????????????? 90 ??
????????????????????????????????? ?????
?????????????? 100 ???? ???????????????????
?????????? 100 ??????????
18Circular Queue (????????)
- ?????????????????????? ???????????????????????????
??????????????????????????????????????
????????????????????????? ???? ????????????????/??
?????????????? ???????????????????????????????????
?? 6 ??? (6 ??) ????????????????????
????????????????????????????????????????????? ?
??????????????
19Circular Queue (????????)
- ???????????? A-F ???????? 1 - 6 ?????????? 1 ???
A ????????????????(?????????) ?????????? A
???????????? ?????????????????????????????????????
????????? A ??????? ????????????? ????? B
???????????????? ??????????????????
?????????????? B ??????? ???????????????? ?
??????????????? ?????????????? ???????????????????
????? ???????? (Circular Queue)
20???????????Operation??? Circular Queue
- ???????????????????????????????1. FIFO (First In
First Out) ???????????????2.
????????????????????????? insert ???????? Queue
??? 3. ????????????????? queue ?????????????????
1 ?????? ? ?????? ??????????? queue
??????????????????????????????????? queue - Operation ??? circular queue1. Insert
???????????????????? (?????)2. Delete
??????????????????????? (??)
21?????????????????????????? Circular Queue
- ???????????????? Queue ????????????? 6 ???
???????????????????? 0 ????????? 5
22?????????????????????????? Circular Queue
23?????????????????????????? Circular Queue
24?????????????????????????? Circular Queue
- ?????????????????????????? ???????????????? Front
??? Rear ???????????????????
???????? Error E ??????? Queue Empty Error O
??????? Queue Overflow
25Algorithm Insert
- Algorithm Insert1. ????????????????? ? (
??????????????? Rear Front ? )-
??????????????????????????? "Queue Overflow"
????????????????2. ?????? Rear ??????????3.
??????????????????4. ?????????? Front ???? -1
??????? (???????????????????????????????????????)
- ?????? ??? Front 0 ( Front ???????????????????
??????????)
26Flowchart Insert
27Program
- ???? Pascal
- Procedure insert ( x integer) var next
integerBeginnext (rear1) mod 5 if
nextfront then write ( ' Queue Overflow ' )else
beginrear next queuerear x if front
-1 then front0endEnd
28Program
- ???? C
- Insert(int x) int nextnext (Rear1) n
if (next Front) printf(" Queue Overflow
")return 0Rear next QueueRear x
if (Front -1) Front 0
29Algorithm Delete
- Algorithm Delete1. ???????????????????????? ?
(Front -1 ? )2. ?????????????????3.
???????????????????????????????????????????
(Front Rear ? )- ?????? ??? Front ??? Rear
???? -1 (???????????????????????????)- ?????????
????????? Front ??????????????
30Flowchart Delete
31Program
- ???? Pascal
- Procedure delete (Var x integer) Beginif
front -1 then write ( ' Queue Empty ' ) else
beginx QueueFront if frontrear
thenbegin front -1 rear -1 end else
front (front1) mod 5end End
32Program
- ???? C
- Delete()if (Front-1) printf(" Queue Empty
" )return 0x QueueFrontif
(FrontRear) FrontRear-1else Front
(Front1) n return x