home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX10012.CPP
- //--------------------------------------------------------------
- // member functions of the PhoneNum, List and ListIter classes
- //--------------------------------------------------------------
-
- // files in this example:
- // %F,15,EX10011.H%EX10011.H definition of the class String
- // %F,15,EX10012.H%EX10012.H definition of the classes
- // PhoneNum, List, and ListIter
- // %F,15,EX10013.H%EX10013.H definition of the class PhoneBk
- // %F,15,EX10011.CPP%EX10011.CPP member functions of the class String
- // EX10012.CPP this file
- // %F,15,EX10013.CPP%EX10013.CPP member functions of the class PhoneBk
- // %F,15,EX1001.CPP%EX1001.CPP main() to exercise this class
-
-
- #include "EX10012.H"
- #include <iostream.h>
-
-
- //--------------------------------------------------------------
- // member funtions of the PhoneNum class
- //--------------------------------------------------------------
-
- ostream& PhoneNum::print(ostream& os)
- { name.print(os)
- << "\t"
- << tel
- << "\t"
- << endl;
- return os;
- }
-
-
- //--------------------------------------------------------------
- // member functions of the List class
- //--------------------------------------------------------------
-
-
- List::~List ()
- { ListIter next(*this);
- PhoneNum* entry;
- while ( ( entry = next() ) != NULL )
- { cout << "destroying: ";
- entry-> print(cout);
- delete entry; }
- }
-
- PhoneNum* List::insert(char* who, long telnum, ListIter next )
- {
- PhoneNum* entry = new PhoneNum( who, telnum);
- if ( entry == NULL ) return entry;
- PhoneNum* prior = next.prev(entry);
- if ( prior == NULL )
- {
- entry->link = first;
- first = entry;
- }
- else
- { entry->link = prior->link;
- prior->link = entry;
- }
- return entry;
- }
-
- void List::del(PhoneNum* entry, ListIter next)
- {
- if ( entry == NULL )
- return;
- PhoneNum* prior = next.prev(entry->link);
- if (entry == first )
- { first = entry->link;
- delete entry;
- }
- else
- { prior->link = entry->link;
- delete entry;
- }
- }
-
-
- //--------------------------------------------------------------
- // member functions of the ListIter class
- //--------------------------------------------------------------
-
-
- PhoneNum* ListIter::operator() ()
- {
- if( current == NULL )
- { prior = NULL;
- current = list->first;
- }
- else
- { prior = current;
- current = current->link;
- }
- return current;
- }
-
- PhoneNum* ListIter::prev( PhoneNum* entry)
- { current = entry;
- return prior;
- }
-
-