aboutsummaryrefslogtreecommitdiff
path: root/7.5/stk.c
diff options
context:
space:
mode:
Diffstat (limited to '7.5/stk.c')
-rw-r--r--7.5/stk.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/7.5/stk.c b/7.5/stk.c
new file mode 100644
index 0000000..ea10221
--- /dev/null
+++ b/7.5/stk.c
@@ -0,0 +1,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;
+}