ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/NullNode.hpp
(Generate patch)

Comparing NullNode.hpp (file contents):
Revision 5 by Douglas Thrift, 2004-05-13T22:47:11-07:00 vs.
Revision 6 by Douglas Thrift, 2004-05-13T23:17:43-07:00

# Line 17 | Line 17 | private:
17          bool null;
18   public:
19          NullNode() : next(NULL), previous(NULL), null(true) {}
20 <        NullNode(const Type& value) : value(value), next(NULL), previous(NULL),
21 <                null(false) {}
20 >        NullNode(const Type& value) : value(value), next(NULL), previous(NULL), null(false) {}
21          ~NullNode() {}
22          void setValue(const Type& value) { this->value = value; }
23          const Type& getValue(void) const { return value; }
# Line 30 | Line 29 | public:
29          void setPrevious(NullNode<Type>* previous) { this->previous = previous; }
30          NullNode<Type>* getNext(void) const { return next; }
31          NullNode<Type>* getPrevious(void) const { return next; }
32 <        bool contains(const Type& value, NullNode<Type>* end);
32 >        bool contains(const Type& value, NullNode<Type>* end, bool forward = true);
33 >        void remove(const Type& value, NullNode<Type>* end, bool forward = true);
34   };
35  
36   template<typename Type>
# Line 78 | Line 78 | void NullNode<Type>::removePrevious(void
78   }
79  
80   template<typename Type>
81 < bool NullNode<Type>::contains(const Type& value, NullNode<Type>* end)
81 > bool NullNode<Type>::contains(const Type& value, NullNode<Type>* end, bool forward)
82   {
83 <        NullNode<Type>* another = next != NULL ? next : previous;
83 >        NullNode<Type>* another = forward ? next : previous;
84  
85          if (null && end == this)
86          {
# Line 93 | Line 93 | bool NullNode<Type>::contains(const Type
93          else return another->contains(value, end);
94   }
95  
96 + template<typename Type>
97 + void NullNode<Type>::remove(const Type& value, NullNode<Type>* end, bool forward)
98 + {
99 +        NullNode<Type>* another = forward ? next : previous;
100 +
101 +        if (!null && value == this->value)
102 +        {
103 +                next->previous = previous;
104 +                previous->next = next;
105 +                
106 +                delete this;
107 +        }
108 +        else if (end != this) another->remove(value, end, forward);
109 + }
110 +
111   #endif // _NullNode_hpp_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines