#include <iostream>
using namespace std;
template <typename T>
struct Node
{ Node(T& d):c(d),next(0),pref(0){}
T c;
Node *next,*pref;
}; // define a struct template
template <typename T>
class List
{ Node<T> *first,*last;
public:
List();
void add(T& c);
void remove(T& c);
Node<T>* find(T& c);
void print();
~List();
}; // declare a class template
template <typename T>
List<T>::List():first(0),last(0){}
// define struct function of List
template <typename T>
void List<T>::add(T& n)
{ Node<T>* p = new Node<T>(n);
p->next=first;
first=p;
(last ? p->next->pref : last) = p;
} // define member function of List: add(T& n)
template <typename T>
void List<T>::remove(T& n)
{ Node<T>* p = find(n);
if (p!=0)
{ (p->next ? p->next->pref : last) = p->pref;
(p->pref ? p->pref->next : first)= p->next;
delete p;
}
} // define member function of List: remove(T& n)
template <typename T>
Node<T>* List<T>::find(T& n)
{ for (Node<T>* p=first; p; p=p->next)
if (p->c==n) return p;
return 0;
} // define member function of List: find(T& n)
template<typename T>
List<T>::~List()
{ for (Node<T>* p; p=first; delete p)
first=first->next;
} //define destruct function of List
template <typename T>
void List<T>::print()
{ for (Node<T>* p=first; p; p=p->next)
cout << p->c << " ";
cout << "/n";
} // define member function of List: print()
int main()
{ List<int> iList;
int b1=2, b2=5, b3=9, b4=3;
iList.add(b1);
iList.add(b2);
iList.add(b3);
iList.add(b4);
iList.print();
iList.remove(b2);
iList.print();
return 0;
}
using namespace std;
template <typename T>
struct Node
{ Node(T& d):c(d),next(0),pref(0){}
T c;
Node *next,*pref;
}; // define a struct template
template <typename T>
class List
{ Node<T> *first,*last;
public:
List();
void add(T& c);
void remove(T& c);
Node<T>* find(T& c);
void print();
~List();
}; // declare a class template
template <typename T>
List<T>::List():first(0),last(0){}
// define struct function of List
template <typename T>
void List<T>::add(T& n)
{ Node<T>* p = new Node<T>(n);
p->next=first;
first=p;
(last ? p->next->pref : last) = p;
} // define member function of List: add(T& n)
template <typename T>
void List<T>::remove(T& n)
{ Node<T>* p = find(n);
if (p!=0)
{ (p->next ? p->next->pref : last) = p->pref;
(p->pref ? p->pref->next : first)= p->next;
delete p;
}
} // define member function of List: remove(T& n)
template <typename T>
Node<T>* List<T>::find(T& n)
{ for (Node<T>* p=first; p; p=p->next)
if (p->c==n) return p;
return 0;
} // define member function of List: find(T& n)
template<typename T>
List<T>::~List()
{ for (Node<T>* p; p=first; delete p)
first=first->next;
} //define destruct function of List
template <typename T>
void List<T>::print()
{ for (Node<T>* p=first; p; p=p->next)
cout << p->c << " ";
cout << "/n";
} // define member function of List: print()
int main()
{ List<int> iList;
int b1=2, b2=5, b3=9, b4=3;
iList.add(b1);
iList.add(b2);
iList.add(b3);
iList.add(b4);
iList.print();
iList.remove(b2);
iList.print();
return 0;
}