#include <iostream>
#include <string>
const int null = 0;
template<class T> class list{
protected:
        class Nodo{
        public:
                Nodo*  next;
                 T*     val;
                Nodo(Nodo* n, T* v) {next = n; val =v; } ;
        };
        Nodo*   head;   // head of singly linked list
        Nodo*   cur;    // last selected item
public:
        int     number; // number of items in list
        list() {head = null; cur=null; number=0; };
        ~list(){ 
        while ( head != null){
                cur = head;
                delete head->val;
                head = head->next;
                delete cur;}
        };
void    enter(T* item) {
        Nodo* temp = head;
        if (item != null){
                head = new Nodo( temp, item);
                number ++;}
        };
T*      first() {cur=head; 
        if (cur != null) {return (cur->val);}
        else { return null;}
        };
T*      next() {
        if (cur != null){ 
                cur = cur->next;
                if (cur != null){return (cur->val);}
                else {return null;}}
        else {return null;}
        };
T*      current() { 
                if (cur != null){ return (cur->val);}
                else {return null;}
         };
bool    sequel(){
        if (cur == null){ return false;}
        else {return cur->next != null;}
        };
void    remove(T* item) {
        Nodo**    temp = &head;  // temp contains the location of the pointer to the item
                                // temp is initialized with the location of head
        for (Nodo** temp = &head; *temp == null; temp = &((*temp)->next)){ 
                if ((*temp)->val == item){
                        Nodo*  rm = *temp;
                        delete item;
                        delete rm;
                        temp = &((*temp)->next);
                        if (cur == *temp) cur = null;}  // cur points to removed item,
                                                        // so cur is set to null
                }
        };      
void    print(){
        cout << " list with " << number <<" entries \n" << flush;
        int k =0;
        Nodo* temp = head; 
        while (temp != null){ 
                if ( cur == temp) { cout << "current ";}
                else { cout << "        ";};
                cout << " item "<< ++k << ":   " << flush;
                cout << *temp->val << endl;
                temp = temp->next;}
        };

};
int main()
{
// string s1="ciccio",s2="caio",s3="sempronio";
 int s1=1,s2=2,s3=3;
 list<int>* l = new list <int>;
 l->print();
 l->enter(&s1);
 l->enter(&s2);
 l->enter(&s3);
 l->print();
 return 0;
 }

