In CS 70, you created linked lists using C++ pointers. However, there
is another way to implement a linked list (or anything else that uses
pointers), which is to use array indices instead of the
next
pointer.
There are two ways to understand this technique:
So if you have an array of Node
s:
struct Node { int data; int next; }; Node stuff[20];and the current node in your list is
stuff[0]
,
then you could access the data in the next node in your list with:
int nextNode = stuff[0].next; int nextData = stuff[nextNode].data;
Last modified April 6, 2002 by geoff@cs.hmc.edu