Stack PowerPoint PPT Presentation

presentation player overlay
1 / 15
About This Presentation
Transcript and Presenter's Notes

Title: Stack


1
Stack
  • ?????????????????????????????????????????????
    (Linear Data Structure) ?????????????????????
    ?????????????? ?????????????????????????????
    ??????????????????????????????????? ????????
    First-In Last-Out FILO

2
Stack
Push A
Push B
Over Flow
Push C
Under Flow
Pop C
Pop B
Pop A
3
Sub Program
Sub C
Sub B
Sub A
Main Program
4
Sub Program
  • Main Program
  • 100
  • 200
  • 300 Call A
  • 400
  • 500 Call B
  • 600 Call C

Sub B 100 200 300 Call C 400 500
Sub C 100 200 300
Sub A 100 200 Call C 300
5
Stack
  • Procedure PUSH(Stack, Top, MaxStk, Item)
  • ??????????????????? Item ????? Stack
  • If Top MaxStk Then Print Over flow and
    Return
  • Set Top Top1
  • Set StackTop Item
  • Return.

Procedure POP(Stack, Top, Item) ?????????????????
???????? Item ??? Top ??? Stack If Top 0 Then
Print Under flow and Return Set Item
StackTop Set Top Top-1 Return.
6
Police notation
  • ????????????????????????????????????????????????
    ??????????????? ??????????????????????????????????
    ?????????????? ????
  • 235

Operator
Operand
Police notation ??????????????????????????????????
??????????????????????? ??????????? (Jan
Lukasiewick) ?????????????????????????????????????
?????????????
(52)3 (52)3 (52)3 523
7
Police notation
8
Police notation
  • Algorithm ?????????? Infix ???? Postfix
  • ??? EXP ???????????????????, Stack ???? Stack ??
    ? ???NEXP ???????????????? Postfix
  • Scan ???????????????????
  • ????? Operand ??????????? NEXP
  • ????? ( ??? Push ???? Stack
  • ????? Operator ???
  • ??? Pop ??? Operator ???????? Stack ????????????
    Operator ?????????????????? NEXP ??????
  • ????? Operator ????? ???????????? Stack ???
  • ????? ) ???
  • ??? Push ??? Operator ???????????????? NEXP
    ?????? ????????? ?? (
  • Push ( ????
  • ???????? 1 ???????? ? ?? ??????? EXP ???
  • ???????????

9
Police notation
  • ???????????????????? (10/2-2)22 ???? Postfix

10
Police notation
  • Algorithm ??????????? Postfix
  • Scan ???????????????????
  • ????? Operand ??? Push ???????? Stack
  • ????? Operator ???
  • Pop ??? Operand ????? 2 ???
  • ??????????????
  • ????? Push ????????????????? Stack
  • ???????? 1 ????????? ????? Postfix ???
  • Pop ?????????????? ??? Stack ???????????????
  • ???????????

11
Police notation
  • ?????????????????? 10,2,/,2,-,2,,2,
    ??????????????? Postfix ????

12
Queue
  • Queue ???? List ??????????? (Linear Data
    Structure) ???????????? Stack ????????????????????
    ?? Queue ???????? 2 ??? ???
  • ??? (Head)
  • ???? (Tail)
  • ????????????????????????????????????????
    ???????? (Tail) ???Queue ???????????? (Head) ???
    Queue ???? Queue ?????????????????????? ????????
    ??????? (First-In First-Out FIFO)

Head
Tail
13
Queue
Delete A
H
T
H
T
Insert A
Delete B
H
T
H
T
Insert B
Insert A
Queue Overflow
H
T
Insert C
Delete C
H
T
H
T
Queue Overflow
Insert D
Delete A
Queue Underflow
14
Circular Queue
Delete A
H
T
H
T
Insert A
Delete B
H
T
H
T
Insert B
Insert A
H
T
H
T
Insert C
Insert B
H
T
H
T
Queue Overflow
Insert D
15
Priority Queue
  • ???? Queue ???????????????????????????????????????
    ??????????
  • ??????????????????????????????????????????????????
  • ????????????????????????????????????????
    ??????????????????????????????????????
Write a Comment
User Comments (0)
About PowerShow.com