In graph theory terms, the outline is a Tree, and each entry in the tree
is a Node.
The classic set of pointers for navigating a structured tree (where you
care what order the nodes appear in) labels each node with:
Father -- Immediate parent (higher level) node
Son -- First subnode (if any)
Brother -- Next subnode (if any) on same level with same parent
Obviously, the names of these labels were set before we became gender
conscious :-)
In your example, the pointers for the "1" node would be: Father "a", Son
nil, Brother "2". For the "a" node: Father "I", son "1", Brother nil.
This structure allows easily changing the structure of a tree. Note
that about half of the son and brother pointers will be nil.
When you are simply visiting the nodes of a tree (for example, to
display it. or to search for text in one of the nodes), you want to do a
Preorder Traversal -- first visit the parent, then visit the children,
in order. It is useful to store this traversal information in a Thread
pointer. In terms of your outline, the thread pointer would read down
the page. In your example, Thread("I") is "a", Thread("a") is "1",
Tread("1") is "2", and Thread("2") is either nil or "I" (it can be
worked either way).
In "pure" Pascal, pointers are explicit, and and use the ^ operator to
follow (dereference) a pointer. In Delphi, pointers are often implicit,
and it may not be obvious when you are using a pointer and when you are
using a copy of a structure. But pointers are at the heart of Delphi's
object oriented structures.
One of the classic references to trees and traversals is the book Data
Structures by Horowitz and Sahni (circa mid-1970s). I'm sure there are
newer references that are equally good.
I hope this reply gives you enough "buzz words" to search on to find
more details. Or feel free to post a follow up.
Rainer von Saleski
_______________________________________________
Delphi mailing list -> [email protected]
http://lists.elists.org/cgi-bin/mailman/listinfo/delphi