指针链表类
麻烦各位帮忙看看,哪错了,该怎么修改#include <iostream>
using namespace std;
struct node
{
int data;
struct node *next;
};
class list
{
private:
node *head;
node *tail;
int length;
public:
list()
{head=NULL;tail=NULL;}
void insert(int x)
{
if(head=new node) cout<<"this is a new list"<<endl;
node *p;
p=new node;
p->next=NULL;
p->data=x;
if(p->data==NULL) cout<<"error"<<endl;
if(head->next==NULL)
head=p;
else
tail->next=p;
tail=p;
length++;
}
void put()
{
node *q;
q=new node;
q->next=NULL;
if(head->next=NULL) cout<<"error"<<endl;
while(!head->next)
{
cout<<q->data<<endl;
q=q->next;
}
cout<<length<<endl;
}
~list()
{ node *q=NULL;
while(head)
{
q=head;
head=head->next;
delete q;
}
head=NULL;
tail=NULL;
}
};
void main()
{
list obj1;
int x;
cout<<"print x"<<endl;
cin>>x;
obj1.insert(x);
obj1.put();
}
[ 本帖最后由 ou1111 于 2010-10-29 12:58 编辑 ]