|
|
 |
|
|
|
|
28: // Show (displays the value) and Compare / (returns relative position)
29: class Data
30: {
31: public:
32: Data(int val) :myValue(val){}
33: ~Data()
34: {
35: cout << Deleting Data object with value: ;
36: cout << myValue << \n ;
37: }
38: int Compare(const Data &);
39: void Show() { cout << myValue << endl; }
40: private:
41: int myValue;
42: };
43:
44: // compare is used to decide where in the list
45: // a particular object belongs.
46: int Data::Compare(const Data & theOtherObject)
47: {
48: if (myValue < theOtherObject.myValue)
49: return kIsSmaller;
50: if (myValue > theOtherObject.myValue)
51: return kIsLarger;
52: else
53: return kIsSame;
54: }
55:
56: // Another class to put into the linked list
57: // Again, every class in this linked list must support // two methods:
58: // Show (displays the value) and Compare // (returns relative position)
59: class Cat
60: {
61: public:
62: Cat(int age): myAge(age){}
63: ~Cat()
64: {
65: cout << Deleting ;
66: cout << myAge << years old Cat.\n ;
67: }
68: int Compare(const Cat &);
69: void Show()
70: {
71: cout << This cat is ;
72: cout << myAge << years old\n ;
73: } |
|
|
|
 |
|
|
|
|
continues |
|
|
|
|
|