#include <stdio.h>
#define NULL 0
typedef struct
{
int n;
int i;
int a;
int f;
}whatever;
typedef struct record
{
whatever info;
struct record *link;
}stackrecord, *stack;
setstack(ps)
/* Initializes the stack s to empty */
stack *ps;
{
*ps = NULL;
}
empty(ps)
stack *ps;
{
return(*ps == NULL);
}
push(pnewrecord,ps)
stackrecord *pnewrecord;
stack *ps;
{
stackrecord *newentry;
newentry = malloc(sizeof(stackrecord));
newentry->info = pnewrecord->info;
newentry->link = *ps;
*ps = newentry;
}
pop(ps,pvalue)
/* Copies the contents of the top record
of stack s into value and removes the
record from the stack
*/
stack *ps;
stackrecord *pvalue;
{
if(!empty(ps))
{
pvalue->info = (*ps)->info;
*ps = (*ps)->link;
}
else
underflow(ps);
}
overflow(ps);
/* Prints a message that the stack has overflowed */
stack *ps;
{
printf(" The stack has overflowed \n");
}
underflow(ps);
/* Prints a message that the stack has underflowed */
stack *ps;
{
printf(" The stack has underflowed \n");
}