home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The C Users' Group Library 1994 August
/
wc-cdrom-cusersgrouplibrary-1994-08.iso
/
listings
/
v_10_03
/
1003020b
< prev
next >
Wrap
Text File
|
1991-12-19
|
500b
|
37 lines
#include <stdio.h>
#define STACK_SIZE 30
static int stack[STACK_SIZE];
static size_t stack_ptr = 0;
void push(int value)
{
#ifdef TRACE
printf("pushing: %c\n", value);
#endif
if (stack_ptr == STACK_SIZE)
printf("Stack is full\n");
else
stack[stack_ptr++] = value;
}
int pop(void)
{
if (stack_ptr == 0) {
printf("Stack is empty\n");
return 0;
}
#ifdef TRACE
printf("popping: %c\n", stack[stack_ptr - 1]);
#endif
return stack[--stack_ptr];
}