< previous page page_414 next page >

Page 414
LISTING 23.2 continued
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
58:      // Again, every class in this linked list must support // two methods:
59:      // Show (displays the value) and Compare // (returns relative position)
60:      class Cat
61:      {
62:      public:
63:         Cat(int age): myAge(age){}
64:         ~Cat(){cout <<  Deleting  << myAge <<  years old Cat.\n ;}
65:         int Compare(const Cat &);
66:         void Show() { cout <<  This cat is  << myAge <<  years old\n ; }
67:      private:
68:         int myAge;
69:      };
70:
71:
72:      // compare is used to decide where in the list
73:      // a particular object belongs.
74:      int Cat::Compare(const Cat & theOtherCat)
75:      {
76:         if (myAge < theOtherCat.myAge)
77:            return kIsSmaller;
78:         if (myAge > theOtherCat.myAge)
79:            return kIsLarger;
80:         else
81:            return kIsSame;
82:      }
83:
84:
85:      // ADT representing the node object in the list
86:      // Every derived class must override Insert and Show
87:      template <class T>
88:      class Node
89:      {
90:      public:
91:         Node(){}
92:         virtual ~Node(){}
93:         virtual Node * Insert(T * theObject)=0;
94:         virtual void Show() = 0;
95:      private:
96:      };
97:
98:      template <class T>
99:      class InternalNode: public Node<T>
100:     {
101:     public:
102:        InternalNode(T * theObject, Node<T> * next);
d5ef64f4d3250b96ba5c07ca5bbc2f56.gif
continues

 
< previous page page_414 next page >

If you like this book, buy it!