/////// File: ArbList.h /////// #ifndef Arblist_SEEN__ #define Arblist_SEEN__ // linked list of arbitrary entries #include typedef void *Arbent; class ArbCell { friend class ArbList; private: Arbent item; ArbCell* next; ArbCell(Arbent c = NULL, ArbCell* ptr = NULL) : item(c), next(ptr) { } // constructor }; typedef int (* EQ_FN)(Arbent, Arbent); // equality tester typedef void (* DISP_FN)(Arbent); // item displayer class ArbList { friend class ArbList_ac; public: ArbList() // empty list constructor : head(NULL), equal(NULL), dispfn(NULL) { } ArbList(Arbent c, EQ_FN eq, DISP_FN d)// list with first cell : head (new ArbCell(c,NULL)), equal(eq), dispfn(d) { } ArbCell* first() const { return head; } // first cell static ArbCell* next(ArbCell* p) { return (p ? p->next : p); } // next cell static int is_end(ArbCell* p) { return(p == NULL); } // end test ArbCell* last(); // last cell ArbCell* find(Arbent c); // first item equals c int substitute(Arbent r, Arbent s); // r for first s on list int remove(Arbent c); // c from entire list void remove(ArbCell* cell); // remove given cell int shorten(int n); // remove first n cells static Arbent content(ArbCell* p) { return p->item; } int put_on(Arbent c); // insert in front int insert(Arbent c, ArbCell* cell);// insert after cell int append(Arbent c) // insert at end { return insert(c, last()); } int is_empty() { return is_end(head); } void display(ArbCell* p); // display from p to end void display() { display(head); } // display whole list ~ArbList(); // destructor private: ArbCell* head; // first cell of list void free(); // free all cells EQ_FN equal; DISP_FN dispfn; }; #endif