Prev | Current Page 207 | Next

Jon Skeet

"C# in Depth: What you need to master C# 2 and 3"

The nongeneric version
supports more direct access, and a private method exists in the generic version,
but it??™s not much use while it??™s private. SortedDictionary<,> doesn??™t
support any of these operations.
If you want to see either of these classes in action, use listing 3.1 as a good starting
point. Just changing Dictionary to SortedDictionary or SortedList will ensure that
the words are printed in alphabetical order, for example.
Our final collection class is genuinely new, rather than a generic version of an
existing nongeneric type. It??™s that staple of computer science courses everywhere: the
linked list.
3.5.5 LinkedList
I suspect you know what a linked list is. Instead of keeping an array that is quick to
access but slow to insert into, a linked list stores its data by building up a chain of
nodes, each of which is linked to the next one. Doubly linked lists (like
LinkedList) store a link to the previous node as well as the next one, so you can
easily iterate backward as well as forward.
102 CHAPTER 3 Parameterized typing with generics
Linked lists make it easy to insert another node into the chain??”as long as you
already have a handle on the node representing the insertion position. All the list
needs to do is create a new node, and make the appropriate links between that node
and the ones that will be before and after it.


Pages:
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219