

The data of Figure 4.21 is shown in Figure 4.22 in a TreeView control. Notice that there is only one route from child nodes to their parent nodes, which means that you can instantly locate the country or continent of a city. The country node is the city node’s parent node. You can also start with a city and find its country.

There’s no property that makes a node unique in the tree structure or even in its own branch. You can have identically named nodes in the same branch - as unlikely as this might be for a real application. Moreover, the TreeView control doesn’t require that the items be unique. Note: The items displayed on a TreeView control are just strings. If it’s not under the appropriate country node, it doesn’t exist. Finally, you can find the city you’re looking for. Then you must find the country (in the selected continent) to which the city belongs. To locate a city, you must start at the root node and select the continent to which the city belongs. The end nodes, which don’t lead to any other nodes, are called leaf nodes or end nodes. If you try to visualize this structure as a real tree, think of it as an upside-down tree with the branches emerging from the root. Oddly, the top node is the root of the tree, and the subordinate nodes are called child nodes. You can’t draw large tree structures on paper, but it’s possible to create a similar structure in the computer’s memory without size limitations.Įach item in the tree of Figure 4.21 is called a node, and nodes can be nested to any level. In the same way, every computer file belongs to a folder that may belong to an even bigger folder, and so on up to the drive level. Every city belongs to a country, and every country to a continent. Figure 4.21 depicts a possible organization of continents, countries, and cities as a tree. Every person reports to another person above him or her, all the way to the president or CEO. The organizational chart of a company, for example, is a tree structure. A tree is the most appropriate structure for storing hierarchical information. The TreeView control implements a data structure known as a tree.
