求助!关于栈的模板类的问题
最近写了个用栈实现的程序,编译的时候栈的模板类出现了许多错误,麻烦哪位帮我瞧瞧栈的模板类的代码:
#include<iostream>
using namespace std;
template <class T>
//栈的结点
class Node{
public:
friend class stack <T>;
Node(const T&x);
private:
Node<T> * next;
T data;
};
template<class T>
Node<T>::Node(const T&x){
date=x;
next=0;
}
template<class T>
//栈
class stack{
private:
int n;
Node<t> * top;
public:
stack();
int isempty();
T& head();
stack<T>& push(const T& x);
stack<T>& pop(const T& X);
int count();
~stack(){
Node<t> *p;
while(top){
p=top->next;
delete top;
top=p;
}
}
};
template <class T>
stack<T>::stack(){
n=0;
top=0;
}
template <class T>
int stack<T>::isempty(){
if(top)
return 1;
return o;
}
template <class T>
//返回栈顶的元素
T& stack<T>::head(){
if(top)
exit(1);
return top->date;
}
template <class T>
//进栈
stack<T>& stack<T>::push(const T & x){
Node<T> *P=new Node<T>(x);
p->next=top;
top=p;
return *this;
}
template <class T>
//出栈
stack<T>& stack<T>::pop(const T & x){
Node<T> *p;
p=top;
x=top->date;
top=top->next;
delete p;
return *this;
}
template <class T>
//栈中元素个数
int stack<T>::count(){
if(isempty())
exit(1);
Node<T> *p;
p=top;
while(p){
p=p->next;
n++;
}
return n;
}