
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
642
|
Chapter 11: Data Structures and Algorithms
Contains Left: e
Contains Right: g
g
Contains Left: NULL
Contains Right: NULL
tree.TreeSize: 7
tree.Root.DepthFirstSearch(a).Children: 1
tree.Root.DepthFirstSearch(a).Children: 2
tree.Root.DepthFirstSearch(g).Children: 0
tree.SearchDepthFirst(a): a
tree.SearchDepthFirst(b): b
tree.SearchDepthFirst(c): c
tree.SearchDepthFirst(d): d
tree.SearchDepthFirst(e): e
tree.SearchDepthFirst(f): f
d
Contains Left: NULL
Contains Right: f
e
Contains Left: NULL
Contains Right: NULL
f
Contains Left: e
Contains Right: g
g
Contains Left: NULL
Contains Right: NULL
d
Contains Left: NULL
Contains Right: NULL
Discussion
Trees are data structures in which each node has exactly one parent and possibly
many children. The root of the tree is a single node that branches out into one or
more child nodes. A node is the part of the tree structure that contains data and con-
tains the branches (or in more concrete terms, references) to its children node(s).
A tree can be used for many things, such as to represent a management hierarchy
with the president of the company at the root node and the various vice presidents as
child nodes of the president. The vice presidents may have managers as child nodes,
and so on. A tree can be used to make decisions, where each node of the tree ...