File tree Expand file tree Collapse file tree 1 file changed +56
-1
lines changed Expand file tree Collapse file tree 1 file changed +56
-1
lines changed Original file line number Diff line number Diff line change @@ -55,12 +55,67 @@ class LinkedList {
55
55
Node* ret = n->next ;
56
56
delete n;
57
57
length -= 1 ;
58
- return n-> next ;
58
+ return ret ;
59
59
}
60
60
61
61
Node* last;
62
62
Node* first;
63
63
uint16_t length;
64
64
};
65
65
66
+
67
+ template <typename NodeType>
68
+ class LinkedList2 {
69
+ public:
70
+ LinkedList2 ():last(NULL ),first(NULL ),length(0 ){}
71
+
72
+ void Add (NodeType* item) {
73
+ if (last == NULL ) {
74
+ last = item;
75
+ first = item;
76
+ item->next = NULL ;
77
+ item->prev = NULL ;
78
+ } else {
79
+ last->next = item;
80
+ item->prev = last;
81
+ item->next = NULL ;
82
+ last = item;
83
+ }
84
+ length += 1 ;
85
+ }
86
+
87
+ template <typename SearchParamType>
88
+ NodeType* Find (SearchParamType input, bool (*search_func)(const NodeType*, SearchParamType))
89
+ {
90
+ NodeType* current = first;
91
+ while (current != NULL ) {
92
+ if (search_func (current, input))
93
+ return current;
94
+ current = current->next ;
95
+ }
96
+ return NULL ;
97
+ }
98
+
99
+ NodeType* Remove (NodeType* n) {
100
+ if (!n)
101
+ return NULL ;
102
+ if (first == n)
103
+ first = n->next ;
104
+ if (last == n)
105
+ last = n->prev ;
106
+ if (n->prev )
107
+ n->prev ->next = n->next ;
108
+ if (n->next )
109
+ n->next ->prev = n->prev ;
110
+ NodeType* ret = n->next ;
111
+ delete n;
112
+ length -= 1 ;
113
+ return ret;
114
+ }
115
+
116
+ NodeType* last;
117
+ NodeType* first;
118
+ uint16_t length;
119
+ };
120
+
66
121
#endif
You can’t perform that action at this time.
0 commit comments