使用C++中string,注意包头文件

有全局<<重载(定义为string的友元)

//#include<iostream>
//#include<string>
//using namespace std;
//template<class T>class ListNode;
//template<class T>
//class LinkNode
//{
//public:
//	LinkNode()
//		:_next(NULL)
//	{
//	}
//	friend class ListNode<T>;
//protected:
//	T _data;
//	LinkNode<T>* _next;
//};
//template<class T>
//class ListNode
//{
//public:
//	ListNode();
//	ListNode(const ListNode<T>& list);
//	ListNode<T>& operator=(ListNode<T> list);
//	~ListNode();
//	void PushBack(const T& data);
//	void  PopBack();
//	void  Print();
//protected:
//	LinkNode<T>* BuyNode(const T& data)
//	{
//		LinkNode<T>* tmp = new LinkNode<T>();
//		tmp->_data = data;
//		return tmp;
//	}
//	void Destory(ListNode& list)
//	{
//		if (list._pHead == NULL)
//			return;
//		else if (list._pHead->_next == NULL)
//		{
//			delete  _pHead;
//			_pHead = NULL;
//		}
//		else
//		{
//			LinkNode<T>* cur = list._pHead;
//			while (cur->_next&&cur->_next->_next)
//			{
//				cur = cur->_next;
//			}
//			LinkNode<T>* del = cur->_next;
//			cur->_next = NULL;
//			delete del;
//		}
//	}
//protected:
//	LinkNode<T>* _pHead;
//};
//template<class T> ListNode<T>::ListNode()
//:_pHead(NULL)
//{
//}
//template<class T> ListNode<T>::ListNode(const ListNode<T>& list)
//: _pHead(NULL)
//{
//	LinkNode<T>* cur = list._pHead;
//	while (cur)
//	{
//		PushBack(cur->_data);
//		cur = cur->_next;
//	}
//}
//template<class T>ListNode<T>& ListNode<T>::operator=(ListNode<T> list)
//{
//	swap(_pHead, list._pHead);
//	return*this;
//}
//template<class T> ListNode<T>:: ~ListNode()
//{
//	while (_pHead)
//	{
//		Destory(*this);
//	}
//	_pHead = NULL;
//}
//template<class T>void  ListNode<T>::PushBack(const T& data)
//{
//	if (_pHead == NULL)
//	{
//		_pHead = BuyNode(data);
//	}
//	else
//	{
//		LinkNode<T>* cur = _pHead;
//		while (cur->_next)
//		{
//			cur = cur->_next;
//		}
//		cur->_next = BuyNode(data);
//	}
//}
//template<class T>void  ListNode<T>::PopBack()
//{
//	Destory(*this);
//}
//template<class T>void  ListNode<T>::Print()
//{
//	LinkNode<T>* cur = _pHead;
//	while (cur)
//	{
//		cout << (cur->_data) << "->";
//		cur = cur->_next;
//	}
//	cout << "NULL" << endl;
//}
//void Test1()
//{
//	ListNode<int> l;
//	l.PushBack(1);
//	l.PushBack(2);
//	l.PushBack(3);
//	l.PushBack(4);
//	l.PushBack(5);
//	l.Print();
//	ListNode<int> x;
//	x.PushBack(1);
//	x = l;
//	x.Print();
//	x.PopBack();
//	x.PopBack();
//	x.PopBack();
//	x.PopBack();
//	x.PopBack();
//	x.Print();
//
//}
//void Test2()
//{
//	ListNode<string> l;
//	l.PushBack("abc");
//	l.PushBack("def");
//	l.PushBack("frfe");
//	l.PushBack("afe");
//	l.PushBack("awkkkkkkkkkkkkkkkkkke");
//	l.PushBack("atgr");
//	l.Print();
//	ListNode<string> s;
//	s = l;
//	s.Print();
//	s.PopBack();
//	s.PopBack();
//	s.PopBack();
//	s.PopBack();
//	s.PopBack();
//	s.PopBack();
//	s.PopBack();
//	s.PopBack();
//	s.Print();
//}
//int main()
//{
//	//Test1();
//	Test2();
//	system("pause");
//	return 0;
//}

再接再厉单链表的模板类_单链表的模板类