I am getting errors...please rectify my code or atleast point out where I am wrong
Code:
#include <iostream>#include <conio.h>
using namespace std;
template <class T>
class NODE
{
friend class STACK;
private:
T DATA;
NODE<T> *LINK;
};
template <class T>
class STACK
{
private:
NODE<T> *TOP;
public:
STACK(){TOP=NULL;}
STACK<T> &PUSH(T x);
STACK<T> &POP(T *x);
void Display();
};
template <class T>
STACK<T> &STACK<T>::PUSH(T x)
{
NODE<T> *NEW=new NODE<T>;
NEW->DATA=x;
NEW->LINK=TOP;
TOP=NEW;
return *this;
}
template <class T>
STACK<T> &STACK<T>::POP(T *x)
{
NODE<T> *DEL=TOP;
*x=DEL->DATA;
TOP=TOP->LINK;
delete DEL;
return *this;
}
template <class T>
void STACK<T>::Display()
{
NODE<T> *PTR=TOP;
while(PTR!=NULL)
{
cout<<PTR->DATA<<endl;
PTR=PTR->LINK;
}
}
int main()
{
STACK<int> S;
int s;
S.PUSH(45);
S.PUSH(76);
S.PUSH(44);
S.PUSH(23);
S.POP(&s);
cout<<"popped data : "<<s<<endl;
S.Display();
getch();
return 0;
}