Professional Documents
Culture Documents
59 .
(push) (pop)
.
- `' .
1 n (
)
i, i .
,
i- .
i ''
. ,
i+1
i
. -
( ).
1 .
Algorithm 1
1: Push
2: // p, index, element //
3: ! p
4: ! index element
5: i i + 1
6: p[i] element
7: Push
Algorithm 2
1: Pop
2: // p, index //
3: ! p
4: ! index
5: !
6: ! -
7: i = 0
8:
apotelesma -
9:
10:
apotelesma p[i]
11:
ii-1
12: _
13: // apotelesma //
14: Pop
2 .
Pascal. .
:
1
2
3
program stack_program ;
const
stack_size = 20;
4
5
6
type
stack = array [1.. stack_size ] of integer ;
, stack
array[1..stack_size] of integer
1 stack_size. stack_size
20
.
push listing 1. 1 listing 1
.
. ,
2
Listing 1: push
1
2
3
4
5
6
7
8
9
10
11
Listing 2: pop
1
2
3
4
5
6
7
8
9
10
11
.
.
. 3-4.
false. 7 8
1 true.
2 listing 2.
.
( )
-.
3
.
.
( )
( -).
:
true false
.
functions Pascal .
4 9.
false .
true
.
true.
. Pascal
var , e.
stack.zip