ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/ccscs20/Node.hpp
Revision: 4
Committed: 2004-05-13T17:50:29-07:00 (21 years, 1 month ago) by Douglas Thrift
File size: 1532 byte(s)
Log Message:
Alive!

File Contents

# User Rev Content
1 Douglas Thrift 1 // Node
2     //
3     // Douglas Thrift
4     //
5     // $Id$
6    
7     #ifndef _Node_hpp_
8     #define _Node_hpp_
9    
10     template<typename Type>
11     class Node
12     {
13     private:
14     Type value;
15 Douglas Thrift 4 Node<Type>* next;
16     Node<Type>* previous;
17 Douglas Thrift 1 public:
18     Node() {}
19 Douglas Thrift 4 Node(const Type& value) : value(value), next(NULL), previous(NULL) {}
20 Douglas Thrift 1 virtual ~Node() {}
21 Douglas Thrift 4 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 Douglas Thrift 1 };
32    
33 Douglas Thrift 4 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 Douglas Thrift 1 #endif // _Node_hpp_

Properties

Name Value
svn:eol-style native
svn:keywords Id