aboutsummaryrefslogtreecommitdiff
path: root/stack.c
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2008-05-17 16:03:18 +0000
committerDimitri Sokolyuk <demon@dim13.org>2008-05-17 16:03:18 +0000
commit93ebb28c47aa021378249dcb34f215be14360230 (patch)
tree9c090d512ec8384297fbc5e5c904a4785dfe6713 /stack.c
pvtrace
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;
+}
+