From 93ebb28c47aa021378249dcb34f215be14360230 Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Sat, 17 May 2008 16:03:18 +0000 Subject: pvtrace --- stack.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 stack.c (limited to 'stack.c') 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 + * + */ + +#include + +#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; +} + -- cgit v1.2.3