stack.c
630 Bytes
1
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
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include "stack.h"
#define STACKSIZE 20
struct stack_handle
{
int top; /* pierwsze wolne miejsce na stosie */
int dane[STACKSIZE];
}
struct stack_handle* init()
{
struct stack_handle* s=(struct stack_handle*)malloc(sizeof(struct stack_handle));
s->top=0;
return s;
}
void finalize(struct stack_handle* s)
{
free(s);
}
void clear(struct stack_handle* s)
{
s->top=0;
}
void push(struct stack_handle* s,int a)
{
assert(s->top<STACKSIZE);
s->dane[s->top++]=a;
}
int pop(struct stack_handle* s)
{
assert(s->top>0);
return s->dane[--s->top];
}