home *** CD-ROM | disk | FTP | other *** search
- // \EXAMPLES\EX10012.H
- //--------------------------------------------------------------
- // definition of the class PhoneNum, List, and ListIter
- //--------------------------------------------------------------
-
- // files in this example:
- // %F,15,EX10011.H%EX10011.H definition of the class String
- // EX10012.H this file
- // %F,15,EX10013.H%EX10013.H definition of the class PhoneBk
- // %F,15,EX10011.CPP%EX10011.CPP member functions of the class String
- // %F,15,EX10012.CPP%EX10012.CPP member functions of the classes
- // PhoneNum, List, and ListIter
- // %F,15,EX10013.CPP%EX10013.CPP member functions of the class PhoneBk
- // %F,15,EX1001.CPP%EX1001.CPP main() to exercise this class
-
-
- #ifndef PHLIST_H
- #define PHLIST_H
-
- #include <IOSTREAM.H>
- #include <STDDEF.H>
- #include "EX10011.H"
-
- //--------------------------------------------------------------
- // definition of the class PhoneNum - A node in a linked list
- //--------------------------------------------------------------
-
- class PhoneNum {
- String name;
- long tel;
- PhoneNum* link;
- friend class ListIter;
- friend class List;
- public:
- PhoneNum( char* n="", long tn=0 )
- : name(n), tel(tn), link(NULL) {};
- ~PhoneNum() {};
- void change ( long tn) { tel = tn; };
- long gettel() { return tel; };
- int compare (char* who) { return name.compare (who); };
- ostream& print(ostream& os);
- };
-
-
- //--------------------------------------------------------------
- // definition of the class List - A linked list of PhoneNum
- //--------------------------------------------------------------
-
- class List {
- PhoneNum* first; // list of PhoneNum objects
- friend class ListIter; // iterator class
- public:
- List(): first(NULL) {}; // constructor
- ~List (); // destructor
- PhoneNum* insert(char* who, long telnum, ListIter next );
- void del(PhoneNum* entry, ListIter next); // delete an entry
- };
-
-
- //--------------------------------------------------------------
- // Definition of a class ListIter, iterator for class List
- //--------------------------------------------------------------
-
- class ListIter {
- List* list; // associated List
- PhoneNum* current; // index current entry
- PhoneNum* prior; // index previous entry
- public:
- ListIter(List& l): current(NULL), prior(NULL), list( &l) {};
- ~ListIter() {}; // destructor
- PhoneNum* operator()(); // iterator - overload ()
- PhoneNum* prev(PhoneNum* entry); // get pointer to prior
- };
-
- #endif
-