|
-
October 11th, 2012, 06:38 AM
#2
Re: Pointers - Unsafe
You don't need to use pointers - in C# there are two kinds of types: (1) value types (structs), which are passed around by value, and (2) reference types (classes), instances of which are really references to objects (garbage collected pointers of sort), and are thus effectively passed by reference. Basically, class instances behave akin to C++ pointers, except you don't have to delete them manually, and you're not allowed to do pointer arithmetic.
So, you only need to declare it this way:
Node next;
// or
Node next = null;
And then when you add a node, you simply write:
next = node;
It essentially makes next point to a different object. You continue to use the member access operator (".") as usual.
BTW, if it's relevant, the .NET library comes with a LinkedList<T> generic class (a doubly linked list).
Last edited by TheGreatCthulhu; October 11th, 2012 at 06:41 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|