#include "stdafx.h"
#include"iostream.h"
template <typename T>
struct node{
node(T& d):data(d),next(0),pref(0){}
T data;
node *next,*pref;
};
template<typename T>
class List{
private:
node<T>*first,*last;
public:
List();
void addnode(T&data);
void deletenode(const T&data);
node<T>* findnode(const T& data)const;
void print()const;
~List();
};
template<typename T>
List<T>::List():first(0),last(0){}
template<typename T>
void List<T>::addnode(T& n){
node<T>*p=new node<T>(n);
p->next=first;first=p;
(last ? p->next->pref:last)=p;
}
template<typename T>
void List<T>::deletenode(const T& n){
node<T>* p;
if(!node<T>*p=find(n)) return;
(p->next ? p->next->pref:last)=p->pref;
(p->pref ? p->pref->next:first)=p->next;
delete p;
}
template<typename T>
node<T>* List<T>::findnode(const T& n)const{
for(node<T>*p=first;p;p=p->next)
if(p->data==n) return p;
return 0;
}
template<typename T>
List<T>::~List(){
for(node<T>*p;p=first;delete p)
first=first->next;
}
template<typename T>
void List<T>::print()const{
int i;node<T>*p;
for(p=first->next,i=1;p;p=p->next,i++)
cout<<"第"<<i<<"个结点:"<<p->data<<"\t";
cout<<"\n";
}
void main(){
List<double> dl;
double i;
cout<<"请输入数据1.输入0.退出:"<<endl;cin>>i;
while(i){
cin>>i;
dl.addnode(i);}
dl.print();
List<int> il;
int j;
cout<<"请输入数据1.输入0.退出:"<<endl;cin>>j;
while(j){
cin>>j;
il.addnode(j);}
il.print();
}