aboutsummaryrefslogblamecommitdiff
path: root/7.5/stk.c
blob: ea102213b5e25a0e31fbb073e9cad8af7e8dee46 (plain) (tree)




























                                                     
#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;
}