#ifndef _LIST_H #define _LIST_H #include template class List { private: class Linkable { private: Type dat; Linkable *follower; public: Linkable(Type d) {dat=d;follower=0;} ~Linkable(void) { if(follower) delete follower; } linkto(Linkable *n) {follower=n;} Linkable *next(void) {return follower;} Type & data(void) {return dat;} }; Linkable *first; Linkable *last; int length; public: List(void) {first=last=0;length=0;} ~List(void) {if(first) delete first;} clear() {if(first) delete first;length=0;first=last=0;} int len(void) {return length;} listappend(Type d) { Linkable *n = new Linkable(d); if(!first) { first = last = n; } else { last->linkto(n); last=n; } length++; } int listdelete(int i) { int j; Linkable *cur, *f; if(i<0 || i>=length) return 0; if(i==0) { f = first; first = first->next(); delete f; } else { for(j=0,cur=first ; jnext()); f = cur->next(); cur->linkto(f->next()); if(last==f) last = f->next(); delete f; } length--; return 1; } Type & operator[](int i) { int j; Linkable *cur; if(i<0 || i>=length) {cerr << "List index "<next()); return cur->data(); } int in(const Type d) { int j=0; Linkable *cur=first; for(; (cur)&&(cur->data()!=d); cur=cur->next(), j++); return j