aboutsummaryrefslogtreecommitdiff
path: root/stack.c
diff options
context:
space:
mode:
Diffstat (limited to 'stack.c')
-rw-r--r--stack.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/stack.c b/stack.c
new file mode 100644
index 0000000..254283a
--- /dev/null
+++ b/stack.c
@@ -0,0 +1,62 @@
+/* $Id$ */
+/********************************************************************
+ * File: stack.c
+ *
+ * Simple stack implementation.
+ *
+ * Author: M. Tim Jones <mtj@mtjones.com>
+ *
+ */
+
+#include <assert.h>
+
+#define MAX_ELEMENTS 50
+
+static int stack[MAX_ELEMENTS];
+static int index;
+
+void stackInit( void )
+{
+ index = 0;
+
+ return;
+}
+
+
+int stackNumElems( void )
+{
+ return index;
+}
+
+
+unsigned int stackTop( void )
+{
+ assert( index > 0 );
+
+ return (stack[index-1]);
+}
+
+
+void stackPush( unsigned int value )
+{
+ assert ( index < MAX_ELEMENTS );
+
+ stack[index] = value;
+ index++;
+
+ return;
+}
+
+
+unsigned int stackPop( void )
+{
+ unsigned int value;
+
+ assert( index > 0 );
+
+ index--;
+ value = stack[index];
+
+ return value;
+}
+