1 |
|
---|
2 | Namespace System
|
---|
3 | Namespace Collections
|
---|
4 | Namespace Generic
|
---|
5 |
|
---|
6 |
|
---|
7 | Class LinkedListNode<T>
|
---|
8 | Protected
|
---|
9 | pList As LinkedList<T>
|
---|
10 | pNext As LinkedListNode<T>
|
---|
11 | pPrevious As LinkedListNode<T>
|
---|
12 | tValue As T
|
---|
13 |
|
---|
14 | Public
|
---|
15 | '指定した値を含んだ LinkedListNode クラスの新しいインスタンスを初期化します。
|
---|
16 | Sub LinkedListNode ( value As T )
|
---|
17 | This.tValue = value
|
---|
18 | End Sub
|
---|
19 |
|
---|
20 | Public
|
---|
21 | 'LinkedListNode が属する LinkedList を取得します。
|
---|
22 | Function List () As LinkedList<T>
|
---|
23 | Return This.pList
|
---|
24 | End Function
|
---|
25 |
|
---|
26 | 'LinkedList 内の次のノードを取得します。
|
---|
27 | Function NextNode () As LinkedListNode<T>
|
---|
28 | Return This.pNext
|
---|
29 | End Function
|
---|
30 |
|
---|
31 | 'LinkedList 内の前のノードを取得します。
|
---|
32 | Function PreviousNode () As LinkedListNode<T>
|
---|
33 | Return This.pPrevious
|
---|
34 | End Function
|
---|
35 |
|
---|
36 | 'ノードに格納された値を取得、設定します。
|
---|
37 | Sub Value ( value As T )
|
---|
38 | This.tValue = value
|
---|
39 | End Sub
|
---|
40 | Function Value () As T
|
---|
41 | Return This.tValue
|
---|
42 | End Function
|
---|
43 |
|
---|
44 | Public
|
---|
45 | '現在の Object を表す String を返します。 (Object から継承されます。)
|
---|
46 | Override Function ToString () As String
|
---|
47 | Return This.Value().ToString()
|
---|
48 | End Function
|
---|
49 | End Class
|
---|
50 |
|
---|
51 | Namespace Detail
|
---|
52 |
|
---|
53 | Class _System_LinkedListNode<T>
|
---|
54 | Inherits LinkedListNode<T>
|
---|
55 |
|
---|
56 | Public
|
---|
57 | Sub l ( list As LinkedList<T> )
|
---|
58 | This.pList = list
|
---|
59 | End Sub
|
---|
60 | Sub NextNode ( ByRef nxt As LinkedListNode<T> )
|
---|
61 | This.pNext = nxt
|
---|
62 | End Sub
|
---|
63 | Sub PreviousNode ( ByRef prv As LinkedListNode<T> )
|
---|
64 | This.pPrevious = prv
|
---|
65 | End Sub
|
---|
66 | End Class
|
---|
67 |
|
---|
68 | End Namespace
|
---|
69 |
|
---|
70 |
|
---|
71 | Class LinkedList<T>
|
---|
72 | Inherits ICollection<T>
|
---|
73 |
|
---|
74 | first As LinkedListNode<T>
|
---|
75 | last As LinkedListNode<T>
|
---|
76 | count As Long
|
---|
77 |
|
---|
78 | Public
|
---|
79 | Sub LinkedList ()
|
---|
80 | This.count = 0
|
---|
81 | End Sub
|
---|
82 |
|
---|
83 |
|
---|
84 | /*!
|
---|
85 | @brief LinkedListに実際に格納されているノードの数を取得
|
---|
86 | @author NoWest
|
---|
87 | @date 2008/08/08
|
---|
88 | */
|
---|
89 | Override Function Count () As Long
|
---|
90 | Return This.count
|
---|
91 | End Function
|
---|
92 |
|
---|
93 | /*!
|
---|
94 | @brief LinkedListの最初のノードを取得
|
---|
95 | @author NoWest
|
---|
96 | @date 2008/08/08
|
---|
97 | */
|
---|
98 | Function First () As LinkedListNode<T>
|
---|
99 | Return This.first
|
---|
100 | End Function
|
---|
101 |
|
---|
102 | /*!
|
---|
103 | @brief LinkedListの最後のノードを取得
|
---|
104 | @author NoWest
|
---|
105 | @date 2008/08/08
|
---|
106 | */
|
---|
107 | Function Last () As LinkedListNode<T>
|
---|
108 | Return This.last
|
---|
109 | End Function
|
---|
110 |
|
---|
111 | /*!
|
---|
112 | @brief LinkedListが読み込み専用かどうかを取得する
|
---|
113 | @author NoWest
|
---|
114 | @date 2008/08/08
|
---|
115 | */
|
---|
116 | Override Function IsReadOnly() As Boolean
|
---|
117 | Return False
|
---|
118 | End Function
|
---|
119 |
|
---|
120 | Public
|
---|
121 | /*!
|
---|
122 | @brief LinkedListの末端にノードを追加する
|
---|
123 | @author NoWest
|
---|
124 | @date 2008/08/08
|
---|
125 | @param 追加するオブジェクト
|
---|
126 | */
|
---|
127 | Override Sub Add( value As T )
|
---|
128 | This.AddLast(value)
|
---|
129 | End Sub
|
---|
130 |
|
---|
131 | /*!
|
---|
132 | @brief LinkedList内の既存のノードの後に新しいノードまたは値を追加
|
---|
133 | @author NoWest
|
---|
134 | @date 2008/08/08
|
---|
135 | */
|
---|
136 | Sub AddAfter ( node As LinkedListNode<T>, newNode As LinkedListNode<T> )
|
---|
137 | End Sub
|
---|
138 | Sub AddAfter ( node As LinkedListNode<T>, value As T )
|
---|
139 | End Sub
|
---|
140 |
|
---|
141 | /*!
|
---|
142 | @brief LinkedList内の既存のノードの前に新しいノードまたは値を追加
|
---|
143 | @author NoWest
|
---|
144 | @date 2008/08/08
|
---|
145 | */
|
---|
146 | Sub AddBefore ( node As LinkedListNode<T>, newNode As LinkedListNode<T> )
|
---|
147 | End Sub
|
---|
148 | Sub AddBefore ( node As LinkedListNode<T>, value As T )
|
---|
149 | End Sub
|
---|
150 |
|
---|
151 | /*!
|
---|
152 | @brief LinkedListの先頭に新しいノードまたは値を追加
|
---|
153 | @author NoWest
|
---|
154 | @date 2008/08/08
|
---|
155 | */
|
---|
156 | Sub AddFirst ( newNode As LinkedListNode<T> )
|
---|
157 | End Sub
|
---|
158 | Sub AddFirst ( value As T )
|
---|
159 | Dim newnode = New Detail._System_LinkedListNode()
|
---|
160 | newnode.List(This)
|
---|
161 | newnode.NextNode(This.first)
|
---|
162 | newnode.PreviousNode(Nothing)
|
---|
163 |
|
---|
164 | Dim node = This.first As Detail._System_LinkedListNode
|
---|
165 | If ActiveBasic.IsNothing(node) Then
|
---|
166 | This.first = newnode
|
---|
167 | This.last = newnode
|
---|
168 | Else
|
---|
169 | node.PreviousNode(newnode)
|
---|
170 | This.first = newnode
|
---|
171 | End If
|
---|
172 | This.count++
|
---|
173 | End Sub
|
---|
174 |
|
---|
175 | /*!
|
---|
176 | @brief LinkedListの末尾に新しいノードまたは値を追加
|
---|
177 | @author NoWest
|
---|
178 | @date 2008/08/08
|
---|
179 | */
|
---|
180 | 'Sub AddLast ( newNode As LinkedListNode<T> )
|
---|
181 | ' This.AddLast(newNode.Value() As T)
|
---|
182 | 'End Sub
|
---|
183 | Sub AddLast ( value As T )
|
---|
184 | Dim newnode = New Detail._System_LinkedListNode<T>()
|
---|
185 | newnode.List(This)
|
---|
186 | newnode.NextNode(Nothing)
|
---|
187 | newnode.PreviousNode(This.last)
|
---|
188 |
|
---|
189 | Dim node = This.last As Detail._System_LinkedListNode<T>
|
---|
190 | If ActiveBasic.IsNothing(node) Then
|
---|
191 | This.first = newnode
|
---|
192 | This.last = newnode
|
---|
193 | Else
|
---|
194 | node.NextNode(newnode)
|
---|
195 | This.last = newnode
|
---|
196 | End If
|
---|
197 | This.count++
|
---|
198 | End Sub
|
---|
199 |
|
---|
200 | /*!
|
---|
201 | @brief LinkedListからすべてのノードを削除
|
---|
202 | @author NoWest
|
---|
203 | @date 2008/08/08
|
---|
204 | */
|
---|
205 | Override Sub Clear ()
|
---|
206 | This.count = 0
|
---|
207 | End Sub
|
---|
208 |
|
---|
209 | 'ある要素がLinkedList内に存在するかどうかを判断
|
---|
210 | /* Override Function Contains ( item As T ) As Boolean
|
---|
211 | TODO
|
---|
212 | End Function*/
|
---|
213 |
|
---|
214 | '既存の1次元のArrayにLinkedListをコピーします。
|
---|
215 | /* CopyTo*/
|
---|
216 |
|
---|
217 | /*!
|
---|
218 | @brief 指定した値を含む最初のノードを検索
|
---|
219 | @author NoWest
|
---|
220 | @date 2008/08/08
|
---|
221 | */
|
---|
222 | Function Find( value As T ) As LinkedListNode<T>
|
---|
223 | If ActiveBasic.IsNothing(This.first) Then Return Nothing
|
---|
224 | End Function
|
---|
225 |
|
---|
226 | /*!
|
---|
227 | @brief 指定した値を含む最後のノードを検索
|
---|
228 | @author NoWest
|
---|
229 | @date 2008/08/08
|
---|
230 | */
|
---|
231 | Function FindLast( value As T ) As LinkedListNode<T>
|
---|
232 | End Function
|
---|
233 |
|
---|
234 | /*!
|
---|
235 | @brief IEnumeratorインターフェイスを取得する
|
---|
236 | @author NoWest
|
---|
237 | @date 2008/08/08
|
---|
238 | @return IEnumeratorインターフェイス
|
---|
239 | */
|
---|
240 | Override Function GetEnumerator () As IEnumerator<T>
|
---|
241 | Return Nothing
|
---|
242 | End Function
|
---|
243 |
|
---|
244 | /*!
|
---|
245 | @brief LinkedList内で最初に出現する値/ノードを削除する
|
---|
246 | @author NoWest
|
---|
247 | @date 2008/08/08
|
---|
248 | @return 値が削除されたときはTrue、されなかったときはFlaseが返る
|
---|
249 | */
|
---|
250 | Function Remove ( node As LinkedListNode<T> ) As Boolean
|
---|
251 | End Function
|
---|
252 | Override Function Remove( value As T ) As Boolean
|
---|
253 | This.Remove(This.Find(value))
|
---|
254 | End Function
|
---|
255 |
|
---|
256 | /*!
|
---|
257 | @brief LinkedListの先頭にあるノードを削除
|
---|
258 | @author NoWest
|
---|
259 | @date 2008/08/08
|
---|
260 | */
|
---|
261 | Sub RemoveFirst ()
|
---|
262 | End Sub
|
---|
263 |
|
---|
264 | /*!
|
---|
265 | @brief LinkedListの末尾にあるノードを削除
|
---|
266 | @author NoWest
|
---|
267 | @date 2008/08/08
|
---|
268 | */
|
---|
269 | Sub RemoveLast ()
|
---|
270 | End Sub
|
---|
271 |
|
---|
272 | 'LinkedListを新しい配列にコピーします。
|
---|
273 | /* ToArray*/
|
---|
274 |
|
---|
275 | End Class
|
---|
276 |
|
---|
277 | End Namespace
|
---|
278 | End Namespace
|
---|
279 | End Namespace
|
---|