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

Comparing Node.hpp (file contents):
Revision 3 by Douglas Thrift, 2004-05-12T23:40:15-07:00 vs.
Revision 4 by Douglas Thrift, 2004-05-13T17:50:29-07:00

# Line 12 | Line 12 | class Node
12   {
13   private:
14          Type value;
15 +        Node<Type>* next;
16 +        Node<Type>* previous;
17   public:
18          Node() {}
19 <        Node(const Type& value) : value(value) {}
19 >        Node(const Type& value) : value(value), next(NULL), previous(NULL) {}
20          virtual ~Node() {}
21 <        virtual void setValue(const Type& value) { this->value = value; }
22 <        virtual const Type& getValue(void) const { return value; }
21 >        void setValue(const Type& value) { this->value = value; }
22 >        const Type& getValue(void) const { return value; }
23 >        void addNext(const Type& value);
24 >        void addPrevious(const Type& value);
25 >        void removeNext(void);
26 >        void removePrevious(void);
27 >        void setNext(Node<Type>* next) { this->next = next; }
28 >        void setPrevious(Node<Type>* previous) { this->previous = previous; }
29 >        Node<Type>* getNext(void) const { return next; }
30 >        Node<Type>* getPrevious(void) const { return next; }
31   };
32  
33 + template<typename Type>
34 + void Node<Type>::addNext(const Type& value)
35 + {
36 +        Node<Type>* behind = next;
37 +
38 +        next = new Node<Type>(value);
39 +        next->previous = this;
40 +        next->next = behind;
41 +        behind->previous = next;
42 + }
43 +
44 + template<typename Type>
45 + void Node<Type>::addPrevious(const Type& value)
46 + {
47 +        Node<Type>* ahead = previous;
48 +
49 +        previous = new Node<Type>(value);
50 +        previous->next = this;
51 +        previous->previous = ahead;
52 +        ahead->next = previous;
53 + }
54 +
55 + template<typename Type>
56 + void Node<Type>::removeNext(void)
57 + {
58 +        Node<Type>* behind = next->next;
59 +
60 +        delete next;
61 +
62 +        next = behind;
63 +        next->previous = this;
64 + }
65 +
66 + template<typename Type>
67 + void Node<Type>::removePrevious(void)
68 + {
69 +        Node<Type>* ahead = previous->previous;
70 +
71 +        delete previous;
72 +
73 +        previous = ahead;
74 +        previous->next = this;
75 + }
76 +
77   #endif // _Node_hpp_

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines