#include<iostream>
using namespace std;
template <class T>class LinkList;
template <class T>
class Node
{
private:
T data;
Node<T> *next;
public:
friend class LinkList<T>;
Node(T x,Node *y=NULL):data(x),next(y){}
};
template <class T>
class LinkList
{
private:
Node<T> *head;
public:
LinkList(T a=-1,Node<T> *b=NULL)
{
head=new Node<T>(a,b);
}
LinkList(const LinkList &L)
{
head=new Node<T>;
Node<T>* x=L.head;
while(x->next)
{
x=x->next;
}
}
void InitFormTail(T c)
{
Node<T>* p=head;
while(p->next)
p=p->next;
p->next=new Node<T>(c);
}
void InitFormTail(int a,T c)
{
Node<T> *p=head;
int x=1;
while(p->next && x<a){
p=p->next;
x++;
}
p->next=new Node<T>(c,p->next);
}
void CreateFormTail()
{
T c;
Node<T> *p=NULL,*tail;
tail=head;
tail->next=p;
while(cin>>c)
{
if(!c) break;
p=new Node<T>(c);
tail->next=p;
tail=p;
}
}
void ReadFormTail()
{
Node<T>* p=head;
while(p->next)
{
p=p->next;
cout<<p->data<<" ";
}
}
~LinkList()
{
Node<T>*p;
while(head)
{
p=head->next;
delete head;
head=p;
}
delete head;
}
};
int main()
{
LinkList<int> L;
L.CreateFormTail();
L.ReadFormTail();
return 0;
}
代码先放这,解析以后再补