写个小程序 大家帮梦分析下 什么地方出错的 实现不了功能呢
#include<iostream.h>
template <class T>
class List;
template <class T>
class Node
{T data;
Node *next;
public:
Node(){next=NULL;}
Node(T i,Node *p){data=i;next=p;}
void dispnode()
{cout<<data<<" ";
}
friend class List<T>;
};
template <class T>
class List
{Node<T> *L;
public:
List(){L=new Node<T>;}
~List()
{Node<T> *p=L,*q=p->next;
while(p->next!=NULL)
{delete p;
p=q;
q=p->next;
}
delete p;
}
bool Listempty()
{return (p->next==NULL);
}
int Listsize()
{int n=0;
Node<T> *p=L;
while(p->next!=NULL)
{n++;
p=p->next;
}
return n;
}
void Listpush_back(T x)
{Node<T> *p=L->next;
Node<T> *s;
while(p!=NULL)
{p=p->next;
}
s=new Node<T>;
s->data=x;
p=s;
}
void Listpop_back()
{Node<T> *p=L;
for(int i=0;i<Listsize()-1;i++)
{p=p->next;
p=NULL;
delete p;
}
}
void dispList()
{Node<T> *p=L->next;
while(p!=NULL)
{p->dispnode();
p=p->next;
}
}
};
int main()
{List<int> lst;
lst.Listpush_back(1);
lst.Listpush_back(2);
lst.dispList();
lst.Listpop_back();
lst.dispList();
return 1;
}