aboutsummaryrefslogtreecommitdiff
path: root/7.5/stk.c
blob: ea102213b5e25a0e31fbb073e9cad8af7e8dee46 (plain) (blame)
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
#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <errno.h>
#include "stk.h"

static unsigned top;
double stk[MAXBUFF];

void push(double n)
{
	if (top < MAXBUFF)
		stk[top++] = n;
	else
		error(EXIT_FAILURE, ENOBUFS, "push");
}

double pop(void)
{
	if (top <= 0)
		error(EXIT_FAILURE, ENOBUFS, "pop");

	return stk[--top];
}

void clear(void)
{
	top = 0;
}