/////// File : NList.C /////// // nested list objects #include #include "NList.h" void NList::display(NItem* p, int r /* = 0 */) { cout << "("; while ( p ) { if ( p->l_c ) cout << p->ch; else display(p->lis, 1); if ( p = p->next ) cout << " "; } cout << ")"; if (r == 0 ) cout << "\n"; } int NList::put_on(char c) { NItem* tmp = new NItem(c,head); if ( tmp ) { head = tmp; return(0); } else return(-1); // failed } int NList::put_on(NList& nl) { NItem* tmp = new NItem(nl.head, head); if ( tmp ) { head = tmp; return(0); } else return(-1); // failed } int main() { NList aa('A'), bb('B'), cd('D'); cd.put_on('C'); bb.put_on(cd); aa.put_on(bb); aa.display(); }