blob: f8e96edf6f5e73ac254c42e995c8f7d017af7ded (
plain)
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
|
#include <stdio.h>
#define MAXVAL 100
#define NUMBER '0'
int sp = 0;
double val[MAXVAL];
void
push(double f)
{
if (sp < MAXVAL) {
val[sp++] = f;
} else {
printf("error: stack full, can't push %g\n", f);
}
}
double
pop(void)
{
if (sp > 0) {
return val[--sp];
} else {
printf("error: stack empty\n");
return 0.0;
}
}
double
peek()
{
return val[sp - 1];
}
void
clear()
{
while (sp) {
val[sp--] = 0;
}
}
|