#include <iostream>
#include <memory>


/**//**
* Single linked list.
*/

template<typename _Ty>
class List


{
public:
List() : mNext(NULL), mEnd(this)

{
}

List(const _Ty& _Val) : mVal(_Val), mNext(NULL)

{
mEnd = this;
}
~List()

{
std::cout << "Destory List:" << mVal << std::endl;

if (mNext != NULL)

{
delete mNext;
mNext = NULL;
}
}

public:
List<_Ty>* Next() const

{
return mNext;
}

List<_Ty>* Begin() const

{
return this;
}

List<_Ty>* End() const

{
return mEnd;
}

List<_Ty>* Insert(List<_Ty>* pNext)

{
this->mEnd->_SetNext(pNext);
this->mEnd = pNext->End();

return pNext;
}

List<_Ty>* Insert(const _Ty& _Val)

{
List<_Ty>* pNext = new List<_Ty>(_Val);
return Insert(pNext);
}

private:
void _SetNext(List<_Ty>* pNext)

{
mNext = pNext;
}

private:
_Ty mVal;
List<_Ty>* mNext;
List<_Ty>* mEnd;
};



int main(void)


{

{
std::auto_ptr<List<int> > ptrList(new List<int>(1));
ptrList.get()->Insert(2);
ptrList.get()->Insert(3);
}

system("pause");
return 0;
}