Stacks Code
This set deals with the array implementation of stacks.
The stack is stored in an array, in this case, of integers.
int STK[MAXSTACK];
int TOS = 0; // top of stack pointer
int
pop()
{
// return the integer at the top of the stack
1. if (! is_stk_empty()) {
2. TOS -= 1;
3. return(STK[TOS + 1]);
4. }
5. return -1;
} //pop
void
push(int item)
{
// store item on the top of the stack
1. if (! is_stk_full()) {
2. TOS += 1;
3. STK[TOS] = item;
4. }
} // push
bool
is_stk_full()
{
// Return true if stack is full
1. return(TOS == MAXSTACK)
} // is_stk_full
bool
is_stk_empty()
{
// Return true if stack is empty
1. return(TOS == 0)
} // is_stk_empty