// lifo.cpp  -- Stack of characters (dynamic storage)

#include "lifo.h"

#define NULL 0


// Create and initialize a lifo
// It returns a lifo whose next field is null and 
// whose count is 0
void createLifo(lifo& stack)
{
	stack.next  = NULL;
}


// push a new value into an existing lifo
void push(lifo& stack, char who)
{
	node *a = new node;

	a->next = stack.next;
	a->value = who;
	stack.next = a;
}

// pop a value from a lifo
char pop(lifo& stack)
{
	node *headNode;
	char who;

	if (stack.next != NULL) {
		headNode = stack.next;
		stack.next = stack.next->next;
		who = headNode->value;
		delete headNode;
		return who;
	}
	return '\0'; // You should never execute this
	          // statement (i.e. do not pop
			  // an empty stack)
}

// check if a lifo is empty
int isempty(lifo& stack)
{
	return (stack.next == NULL);
}
