
#includeusing namespace std; template class linkList; template class Node { private: T data; Node *next; public: friend class linkList ; Node(T x,Node *y=NULL):data(x),next(y){} }; template class linkList { private: Node *head; public: linkList(T a=-1,Node *b=NULL) { head=new Node (a,b); } linkList(const linkList &L) { head=new Node ; Node * x=L.head; while(x->next) { x=x->next; } } void InitFormTail(T c) { Node * p=head; while(p->next) p=p->next; p->next=new Node (c); } void InitFormTail(int a,T c) { Node *p=head; int x=1; while(p->next && xnext; x++; } p->next=new Node (c,p->next); } void CreateFormTail() { T c; Node *p=NULL,*tail; tail=head; tail->next=p; while(cin>>c) { if(!c) break; p=new Node (c); tail->next=p; tail=p; } } void ReadFormTail() { Node * p=head; while(p->next) { p=p->next; cout< data<<" "; } } ~linkList() { Node *p; while(head) { p=head->next; delete head; head=p; } delete head; } }; int main() { linkList L; L.CreateFormTail(); L.ReadFormTail(); return 0; }
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)