// --mylist.h--
#ifndef LIST_H
#define LIST_H
#include <iostream>
#include <fstream>
using namespace std;
template<class T>
struct CNode
{
T info;
CNode<T> *next;
};
template<class T>
class CList
{
CNode<T> *tail; //表尾指针
CNode<T> *head; //表头指针
public:
CList(){tail=head=NULL;}
~CList(){Destroy();}
void Destroy(){delete node;delete head;}
//查找
bool Search(T &inform)
{
CNode<T>*newNode=head;
while(newNode)
{
if(newNode->info==inform){cout<<inform<<endl;return true;}
newNode=newNode->next;
}
cout<<"Not found !"<<endl;
return false;
}
//插入---按顺序插入做法
void Insert(T inform)
{
CNode<T>*newNode=new CNode<T>;
newNode->info=inform;
newNode->next=NULL;
tail->next=newNode;
tail=newNode;
delete newNode;
}
//删除
void Delete(T inform)
{
bool found=false;
CNode<T>*newNode=head;
CNode<T>*nextNode;
while(newNode)
{
nextNode=newNode->next;
if(newNode->info==inform)
{
head=nextNode;
found=true; //找到该数据
delete newNode;
}
newNode=newNode->next;
}
if(!found)cout<<"Cann't delete a nonentity information !"<<endl;
}
//退出并保存数据
void quitAndSave(ofstream &os)
{
for(CNode<T> *tempNode=head;tempNode!=NULL;tempNode=tempNode->next)os<<tempNode->T<<endl;
}
};
#endif //LIST_H