#ifndef STACK_H
#define STACK_H
#include <stack>
#include <iostream>

template <class T>
class Stack
{          
	//Our data in the linklist is stored in nodes
	//whichs contains data and next pointers
	struct Node
	{
		T element;
		Node* next;
	};

	//head pointer which points to the first node in the SLL
	Node* m_head;
public:
	Stack(void);
	~Stack(void);
	void PUSH(T value);
	void POP(); 
	T TOP(); 
	void CLEAR();
	void Print();
};

#endif
template <class T> Stack<T>::Stack(void)
{
	m_head = 0;
}

template <class T> Stack<T>::~Stack(void)
{

}

template <class T> void Stack<T>::PUSH(T value)
{
	// Dynamically create a new node
	Node* n = new Node;

	//Set N to value to passed node into fuction
	n->element = value;

	// Set the pointer to the current head
	n->next = m_head;

	// Point head to new headnode
	m_head = n;

}

template <class T> void Stack<T>::POP() 
{
	// create a pointer (tmp) that points to head
	Node* tmp = m_head;

	// move head to tmps next node
	m_head = tmp->next; //alternatively, m_head = m_head->next

	//delete tmp's node
	delete tmp;
}

template <class T> T Stack<T>::TOP()
{
	return m_head->element;
}

template <class T> void Stack<T>::CLEAR()
{
	while(m_head)
	{

		// create a pointer (tmp) that points to head
		Node* tmp = m_head;

		// move head to tmps next node
		m_head = tmp->next; //alternatively, m_head = m_head->next

		//delete tmp's node
		delete tmp;
	}		
}

template <class T> void Stack<T>::Print()
{
	Node* tmp = m_head;
	while(tmp)
	{
		cout << tmp->element << " <- ";

		tmp = tmp->next;
	}
	cout << "X\n";
}