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; } |
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> |
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 |
|
{ |
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_ |