![]() |
#2
m21wo2010-11-11 18:51
|

#include<iostream.h>
template <class T>
struct node
{
T data;
struct node *next;
};
class list
{private:
node *head,*tail;
public:
list()
{head=NULL;tail=NULL;}
void insert(T x)//为什么说没有定义T呢
{
node *p;
p=new node;
p->data=x;
p->next=NULL;
if(head==NULL)
{head=p;p->next=tail;}
else
{ p->next=head;
head=p;}
}
void show()
{
node *p;
p=head;
while(p)
{
cout<<p->data;
p=p->next;
}
}
~list()
{
node *p;
while(head)
{
p=head;
head=head->next;
delete p;
}
head=NULL;
tail=NULL;
}
};
template <class T>
struct node
{
T data;
struct node *next;
};
class list
{private:
node *head,*tail;
public:
list()
{head=NULL;tail=NULL;}
void insert(T x)//为什么说没有定义T呢
{
node *p;
p=new node;
p->data=x;
p->next=NULL;
if(head==NULL)
{head=p;p->next=tail;}
else
{ p->next=head;
head=p;}
}
void show()
{
node *p;
p=head;
while(p)
{
cout<<p->data;
p=p->next;
}
}
~list()
{
node *p;
while(head)
{
p=head;
head=head->next;
delete p;
}
head=NULL;
tail=NULL;
}
};