Node:Data structure diagrams, Next:Dynamic data structures, Previous:Complex data structures, Up:Complex data structures
Sometimes you will want to draw a picture that shows how to solve a problem by displaying how all its parts are connected. Such a picture is called a structure diagram.
Consider a hypothetical application that stores a map of the local
countryside. This program must store information about individual towns
and be able to give directions to the user about how to get from one
town to another. A person driving a car from town to town might use a
map, but the application programmer might use a structure diagram. Here
is a structure diagram for the imaginary town of New Haven, and its
neighboring towns North Haven, East Haven, South Haven, and West Haven:
North Haven ^ | v West Haven <-> New Haven <-> East Haven ^ | v South Haven
Once you have a structure diagram that represents your information,
you can create a data structure that translates the structure diagram
into the computer's memory. In this case, we can create a "town structure"
that contains pointers to the towns that lie at the end of roads in the various
compass directions. The town structure might look something like this:
struct town { struct town *north; struct town *south; struct town *east; struct town *west; char name[50]; };
If the user of this hypothetical application wishes to know what is to
the north of a particular town, the program only has to check that town's
north
pointer.