#include<iostream>
using namespace std;

enum errorcode {success,underflow};


template <class t>
struct node
{
node<t>* link;
t info;


node()
{
top=0;
}

node(t i,node<t>* l=0)
{
link=l;
info=i;
}
};

template <class t>
class stack
{
private :
	node<t>* topp;

public :
	stack();
	bool is_empty();
	void print();
	void push(t e1);
	errorcode pop();
	errorcode top(t &e1);
	//~stack();
	//void operator=(stack &o)
	//stack(stack &o)

};

template <class t>
stack<t>::stack()
{
topp=0;
}

template <class t>
bool stack<t>::is_empty()
{
return(top==0);
}


template <class t>
void stack<t>::print()
{
node<t>* tmp=topp;
for(;tmp!=0;tmp=tmp->link)
	cout<<tmp->info<<"  ";

cout<<endl;
}



template <class t>
void stack<t>::push(t e1)
{
topp=new node<t>(e1,topp);
}



template <class t>
errorcode stack<t>::pop()
{
	if(is_empty())
		return underflow;
	node<t>* tmp=topp;
	topp=topp->link;
	delete tmp;
	return success;

}


template <class t>
errorcode stack<t>::top(t &e1)
{
if(is_empty())
	return underflow;

e1=topp->info;
return success;
}








void main()
{
stack<int> s;

s.print();
s.push(1); 
s.push(5);
s.push(9);
s.push(8);
s.push(4);
s.push(10);
s.print();
int x;
s.top(x);
cout<<x<<endl;
s.pop();
s.pop();
s.pop();

s.print();
s.top(x);
cout<<x<<endl;




}
