Explain how pointer are used to
implement linked list structure.
list is a data structure that is built from structures and pointers. It forms a
chain of"nodes" with pointers representing the links of the chain and
holding the entire thing together.
list can be represented by a diagram like this one: This linked list has four
nodes in it, each with a link to the next node in the series. The last node has
a link to the special value NULL, which any pointer (whatever its type) can
point to, to show that it is the last link in the chain. There is also another
special pointer, called Start (also called head), which points to the first
link in the chain so that we can keep track of it.
the data structure for a linked list
part of a linked list is a structure, which holds the data for each node (the
name, address, age or whatever for the items in the list), and, most
importantly, a pointer to the next node. Here we have given the structure of a
name; // Name of up to 20 letters int age
height; // In metres
*nxt;// Pointer to next node };
node *start_ptr = NULL;
important part of the structure is the line before the closing curly brackets.
This gives a pointer to the next node in the list. This is the only case in C++
where you are allowed to refer to
type (in this case node) before you have even finished defining it!
also declared a pointer called start_ptr that will permanently point to the
start of the list. To start with, there are no nodes in the list, which is why
start_ptr is set to NULL.