?????????????????? Queue - PowerPoint PPT Presentation

1 / 32
About This Presentation
Title:

?????????????????? Queue

Description:

Title: Circular Queue ( ) Author: User Last modified by: ksu Created Date: 7/21/2006 3:18:15 AM Document presentation format – PowerPoint PPT presentation

Number of Views:193
Avg rating:3.0/5.0
Slides: 33
Provided by: acth
Category:
Tags: circular | queue

less

Transcript and Presenter's Notes

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
3
Operation ??? 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 ?????)
5
Implementation Queue
  • ??? Implement Queue ????? 2???????1. Array
    Implementation2. Linked List Implementation

Data Structure
Department of Computer Science
6
Insert 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
7
Flowchat
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
10
Delete 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
11
Flowchat
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
14
Circular Queue (????????)
15
Circular Queue (????????)
  • ???????????????????????????????
  • ??????????????????????????????????????????
    ????????????????????
  • ????????????????????? ?????????????????????
  • ??????????????????????????? (Full Queue)
    ??????????????????????
  • ???????????????? ?????????? F ???????????????????
    ?????? ????????????????
  • ??????????????????????????????????????????????????
    ??????????????
  • (Empty Queue) ???????????????????????????????? F
    ??? R ????????????
  • ?????????????????????? ???????????????????????????
    ?????????????????????
  • ????? F ?????? ???????????????????????????????????
    ????? F ????????????
  • ??????????? (????????????) ???????????????????????
    ?????????

16
Circular Queue (????????)
  • ??????????????????????? ?????????????????????????
    ???????????????
  • ???????????? ?????????????????????????????????????
    ?????????????????
  • ??????????????????????????? ???
    ???????????????????? (Front)
  • ??????????????????????? (Rear)
    ???????????????????????????
  • ???????? ???????? (Circular Queue)

17
Circular Queue (????????)
  • ??????????
  • ??????????????????????????????????????????????????
    ?????????????????? 6 ?????????????
    ??????????????? 0-4 ?????? ??????????????????
    ??????????????????????????????????????????? ????
    ???????????????????????????????? 100 ????
    ??????????????????????????????????????? 100
    ?????????? ??????????????????????? ???????????
    ?????? (Delete) ?????????????????????????????????
    90 ???? ????????????????????? 7 ??
    ???????????????? ???????? ??????????????????? 3
    ?? ????????? 100 ?? ??????????????????????????????
    ????? 90 ???? ?????? ?????????????????????? 90 ??
    ????????????????????????????????? ?????
    ?????????????? 100 ???? ???????????????????
    ?????????? 100 ??????????

18
Circular Queue (????????)
  • ?????????????????????? ???????????????????????????
    ??????????????????????????????????????
    ????????????????????????? ???? ????????????????/??
    ?????????????? ???????????????????????????????????
    ?? 6 ??? (6 ??) ????????????????????
    ????????????????????????????????????????????? ?
    ??????????????

19
Circular 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
25
Algorithm Insert
  • Algorithm Insert1. ????????????????? ? (
    ??????????????? Rear Front ? )-
    ??????????????????????????? "Queue Overflow"
    ????????????????2. ?????? Rear ??????????3.
    ??????????????????4. ?????????? Front ???? -1
    ??????? (???????????????????????????????????????)
    - ?????? ??? Front 0 ( Front ???????????????????
    ??????????)

26
Flowchart Insert
27
Program
  • ???? 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

28
Program
  • ???? C
  • Insert(int x) int nextnext (Rear1) n
    if (next Front) printf(" Queue Overflow
    ")return 0Rear next QueueRear x
    if (Front -1) Front 0

29
Algorithm Delete
  • Algorithm Delete1. ???????????????????????? ?
    (Front -1 ? )2. ?????????????????3.
    ???????????????????????????????????????????
    (Front Rear ? )- ?????? ??? Front ??? Rear
    ???? -1 (???????????????????????????)- ?????????
    ????????? Front ??????????????

30
Flowchart Delete
31
Program
  • ???? 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

32
Program
  • ???? C
  • Delete()if (Front-1) printf(" Queue Empty
    " )return 0x QueueFrontif
    (FrontRear) FrontRear-1else Front
    (Front1) n return x
Write a Comment
User Comments (0)
About PowerShow.com