template <class T, class K>
class OrderedList : public  List<T> {

public:

void insert(T data){
DataNode<T> *current(_head), *previous(NULL);   
if (_head){                        // lista non vuota
  while(current != NULL && (keycmp(current->data(), data) <= 0)){
    previous = current;
     current = current -> right();}
  if (!previous)   // si deve inserire come primo 
    _head=new DataNode<T>(data,current);
   else 
     previous->right()=new DataNode<T>(data,current);
  }
else{_head=_tail=new DataNode<T>(data,NULL);}  //lista vuota
}  // insert

void remove(K key){
DataNode<T> *current(_head), *previous(NULL);   
if (_head){                        // lista non vuota
  while(current != NULL && (keycmp(current->data(), key) < 0)){
    previous = current;
     current = current -> right();  }
  if (keycmp(current->data(),key)==0)   // ok trovato
  if (!previous)   // si deve rimuovere il primo 
   { _head=current->right();
   delete current;}
   else 
     {
    (*previous).Node::operator =(current->right());
    delete current;}
}}  // remove

  // cerca un nodo in base alla chiave 
  // ritorna un puntatore ai dati o NULL se non lo trova
T *retrieve(K key){
DataNode<T> *current(_head);   
if (_head){                        // lista non vuota
  while(current != NULL && (keycmp(current->data(), key) < 0)){
     current = current -> right();  }
  if (keycmp(current->data(),key)==0)   // ok trovato
   return &(current->data());
  else
   return NULL;  
}}  // retrieve
};  //OrderedList<T>

// ordinamento decrescente per gli interi
const int keycmp(const int int1, const int int2) {return int2 - int1;}

main(){
// lista di interi e relativo iteratore
OrderedList<int,int> list;
int ix;
int *pi;
for (ix=0; ix <= 10; ix+=2) list.insert(ix);
for (ix=1; ix <= 10; ix+=2) list.insert(ix);
pi= list.retrieve(0);
if (pi) cout << "retrieve: "<< *pi << endl;
  else cout << "retrieve: non trovato" << endl;
list.remove(5);
printf("list : "); 
ListIterator<int> iter(list);
while (!iter.terminate()) {
   printf("%3d",iter.current());
   iter.succ();
  } 
puts("");
}

Attila.Eng.UniPR.IT> a.out
retrieve: 0
list :  10  9  8  7  6  4  3  2  1  0