#include "Stack.h"
#include <iostream>
#include <cstddef>

using namespace std;

Stack::Stack() {
	top = NULL ;
}

Stack::~Stack() {
	char char_crt ;
	while (!empty())
	char_crt = pop() ; //pop calls delete
}

bool Stack::empty() {
	return (top==NULL) ;
}

void Stack::push (char the_symbol) {
	StackNodePtr temp_ptr ;
	temp_ptr = new StackNode ;
	temp_ptr->data = the_symbol ;
	temp_ptr->next = top ;
	top = temp_ptr ;
}

char Stack::pop() {
	if (empty ()) {
		cout << "Error: popping an empty stack.\n";
		exit (1) ;
	}
	char result = top->data ;
	StackNodePtr temp_Ptr ;
	temp_Ptr = top ;
	top = top->next ;
	delete temp_Ptr ;
	return result ;
}

