/////// File : NList.h /////// // nested list objects #ifndef Nlist_SEEN__ #define Nlist_SEEN__ #include class NItem { friend class NList; private: enum Boolean {FALSE, TRUE}; union { char ch; NItem* lis; }; Boolean l_c; // 0 for list 1 for char NItem* next; NItem(char c = '\0', NItem* ptr = NULL) : l_c(TRUE), ch(c), next(ptr) { } // constructor NItem(NItem* l = NULL, NItem* ptr = NULL) : l_c(FALSE), lis(l), next(ptr) { } // constructor }; class NList { public: NList() : head(NULL) { } // empty list constructor NList(char c) // list with first cell : head (new NItem(c,NULL)) { } int put_on(char c); // put on a char int put_on(NList& c); // put on a nested list void display(NItem* p, int r = 0); // display from p to end void display() { display(head); } // display whole list /* ... */ private: NItem* head; // first cell of list void free(); // free all cells }; #endif