ΑΕΠΠ - Μάθημα 26

  • View
    1.051

  • Download
    0

Embed Size (px)

Transcript

  • .

  • .

    , .

  • .

    , .

    Last In First Out (LIFO)

  • .

    , .

    Last In First Out (LIFO)

  • (push)

  • 45

    (push)

    Push(45)

  • 045

    (push)

    Push(45)Push(0)

  • 140

    45

    (push)

    Push(45)Push(0)Push(14)

  • 20140

    45

    (push)

    Push(45)Push(0)Push(14)Push(20)

  • -5 0

    44 520140

    45

    (push)

    Push(45)Push(0)Push(14)Push(20)Push(5)Push(44)Push(0)Push(-5)

  • -5 0

    44 520140

    45

    (push)

    Push(45)Push(0)Push(14)Push(20)Push(5)Push(44)Push(0)Push(-5)Push(10) !

  • -5 0

    44 520140

    45

    (push)

    Push(45)Push(0)Push(14)Push(20)Push(5)Push(44)Push(0)Push(-5)Push(10) !

    !

  • -5 0

    44 520140

    45

    (pop)

  • 0

    44 520140

    45

    (pop)

    Pop -5

  • 44 520140

    45

    (pop)

    Pop -5Pop 0

  • 520140

    45

    (pop)

    Pop -5Pop 0Pop 44

  • (pop)

    Pop -5Pop 0Pop 44Pop 5Pop 20Pop 14Pop 0Pop 45

  • (pop)

    Pop -5Pop 0Pop 44Pop 5Pop 20Pop 14Pop 0Pop 45Pop ! !

  • (pop)

    Pop -5Pop 0Pop 44Pop 5Pop 20Pop 14Pop 0Pop 45Pop ! !

    !

  • :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

  • 1

    :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

    Push(1)

  • 0

    1

    :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

    Push(1)Push(0)

  • 1

    :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

    Push(1)Push(0)Pop 0

  • 2

    1

    :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

    Push(1)Push(0)Pop 0Push(2)

  • 1

    :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

    Push(1)Push(0)Pop 0Push(2)Pop 2

  • :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

    Push(1)Push(0)Pop 0Push(2)Pop 2Pop 1

  • :Push(1), Push(0), Pop, Push(2), Pop, Pop

    ;

    Push(1)Push(0)Pop 0Push(2)Pop 2Pop 1

    0, 2, 1

  • 11

    55

    24

    5

    4

    3

    2

    1

    .

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    .

    (top)

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    .

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    . , top

    top < 5

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    . , top , top

    top < 5 top top + 1 [top]

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    . , top , top

    top < 5 top top + 1 [top] _

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    , top>=1.

    top >= 1

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    , top>=1. , , [top] .

    top >= 1 [top] top top - 1

  • 11

    55

    24

    5

    4

    3

    2

    1

    top

    , top>=1. , , [top] . .

    top >= 1 [top] top top - 1 _

  • .

    .

    First In First Out (FIFO)

  • .

    .

    First In First Out (FIFO)

  • (enqueue)

  • 20

    (enqueue)

    (20)

  • 20 3

    (enqueue)

    (20)(3)

  • 20 3 2

    (enqueue)

    (20)(3)(2)

  • 20 3 2 0 33

    (enqueue)

    (20)(3)(2)(0)(33)

  • 20 3 2 0 33

    (enqueue)

    (20)(3)(2)(0)(33)(5) !

  • 20 3 2 0 33

    (enqueue)

    (20)(3)(2)(0)(33)(5) !

  • 20 3 2 0 33

    (dequeue)

  • 3 2 0 33

    (dequeue)

    20

  • 2 0 33

    (dequeue)

    20 3

  • 0 33

    (dequeue)

    20 3 2

  • (dequeue)

    20 3 2 0 33

  • (dequeue)

    20 3 2 0 33 - !

  • (dequeue)

    20 3 2 0 33 - !

  • :(0), (21), , (4),

  • 0

    :(0), (21), , (4),

    (0)

  • 0 21

    :(0), (21), , (4),

    (0)(21)

  • 21

    :(0), (21), , (4),

    (0)(21) 0

  • 21 4

    :(0), (21), , (4),

    (0)(21) 0(4)

  • 4

    :(0), (21), , (4),

    (0)(21) 0(4) 21

  • 4

    :(0), (21), , (4),

    (0)(21) 0(4) 21

    0, 21

  • 1 2 3 4 5

    22 0 -5

    .

  • 1 2 3 4 5

    22 0 -5

    front

    .

    2 (front) (rear)

    rear

  • .

    1 2 3 4 5

    22 0 -5

    front rear

  • .

    rear < 5

    1 2 3 4 5

    22 0 -5

    front rear

  • . , rear

    rear < 5 rear rear + 1 [rear]

    1 2 3 4 5

    22 0 -5

    front rear

  • . , rear

    rear < 5 rear rear + 1 [rear] _

    1 2 3 4 5

    22 0 -5

    front rear

  • front

  • front

  • front

  • ( 14)1) 10 : , , , , , , , . . top . . , , , , top ; . .

    2) , , , (. 1 , 2 , 3 4 .) , , , (. 1 , 2 , 3 4 .) ;

    3) 2

    2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72