So why the head and tail? That just makes things easier it’s always nice to be able to quickly get to the first and last node of a list. TListNode *tail // pointer to the node at the top of the list TListNode *head // pointer to the node at the head of the list You need something to keep track of all the node, so in order to do that, we create a List struct: struct tList In ROBOTC, you could represent such a list node with a struct like this: struct tListNode The last pointer in the list is nothing, or NULL. If you were looking at the node with “99” in it, and you wanted to know which one’s the next in line, you’d simply follow the pointer to the next node. What is a linked list, you say? Consider the image below.Įach list element contains a number and a reference (or pointer) to the next node in the list, a bit like a chain of nodes. If you want to know more about stacks, you should check out part 2: You can read about pointers in this tutorial. I will also be covering things like queues, binary trees and other fun stuff. Please note that this is the second instalment of a multi-part tutorial on how you can use pointers in ROBOTC.
Please note that some of the images are based on the ones found in the original WikiPedia article on linked lists. In any case, when ROBOTC implemented pointers, I started working on a little implementation of a linked list in ROBOTC. I don’t pretend to understand the math behind most of them. It was my favourite subject when studying computer science and I have a few good books on the subject. That sounded a lot less geeky in my head, but it’s true.