#include <stdio.h>
#include <assert.h>
#include "Stack.h"

/*NB. assumes a stack of scalar elements  -- L.Allison */

void clear(Stack *S) { *S = NULL; }

int empty(Stack S)
 { return S==NULL ? 1 : 0; }

void push(StackElementType E, /*var*/ Stack *S)
 { Stack T;
   T = (Stack)malloc(sizeof(StackCell));
   T->tl = *S;
   T->elt = E;
   *S = T;
 }

void pop(StackElementType *E, Stack *S)
/* pre: not empty(*S) */
 { Stack T;
   assert( !empty(*S) );
   *E = (*S)->elt;  T = *S;  *S = (*S)->tl;  free(T);
 }

/* Operations on a Stack Implemented by a Linked List */
