basic operations for the stack

setstack(ps)

/* Sets stack s to empty */

stack *ps;

{

(*ps).top = -1;

}

empty(ps)

/* Returns true only if

stack s is empty.

*/

stack *ps;

{

return((*ps).top == -1);

}

push(value,ps)

/* Inserts contents of value as

top entry of stack s.

*/

whatever value;

stack *ps;

{

if ((*ps).top == (LIMIT - 1))

overflow(ps);

else

{

(*ps).top = (*ps).top + 1;

(*ps).stackarray[(*ps).top] = value;

}

}

pop(ps,pvalue)

/* Removes the top entry of stack s

and places its contents in value.

*/

stack *ps;

whatever *pvalue;

{

if (empty(ps))

underflow(ps);

else

{

*pvalue = (*ps).stackarray[(*ps).top];

(*ps).top = (*ps).top - 1;

}

}

overflow(ps)

/* Prints a message when

the stack overflows.

*/

stack *ps;

{

printf("\n stack overflow \n");

}

underflow(ps)

/* Prints a message when

the stack underflows.

*/

stack *ps;

{

printf("\n stack underflow \n");