Tree – It's Upside Down!
As we discussed in the previous section, a tree is nothing but some objects or nodes connected to other nodes via a relationship that results in some sort of hierarchy. If we were to show this hierarchy in a graphical way, it would look like a tree, while the different edges would look like its branches. The main node, which is not dependent on any other node, is also known as a root node and is usually represented at the top. So, unlike an actual tree, this tree is upside down, with the root at its top!
Let's try to construct a structure for a very basic version of an organizational hierarchy.
Exercise 7: Creating an Organizational Structure
In this exercise, we will implement a basic version of the organizational tree we saw in the introduction to this chapter. Let's get started:
- First, let's include the required headers:
#include <iostream>
#include <queue>
- For simplicity, we'll assume that any person can have, at...