随意写了一点,供以后取用。
#include <iostream>
using namespace std;
template <typename t> class lian;
template <typename t> class knot
{
friend class lian<t>;
private:
t value;
knot<t>* next;
public:
knot(t a=0) { value = a; next = NULL; }
};
template <typename t> class lian
{
public:
knot<t>* top;
knot<t>* note;
void set() { note=top = new knot<t>; }
void push(t a)
{
class knot<t>* p;
p = new knot<t>;
p->value = a;
p->next = NULL;
top->next = p;
top = p;
}
bool isempty() { if (note->next == NULL)return true; else return false; }
~lian()
{
class knot<t>* p; p = note; while (note->next != NULL) { p = note;note = note->next; delete p; }
}
};
int main()
{
class lian<int> t;
t.set();
cout << t.isempty();
return 0;
}