int main(int, char* [])
{
using NodeType = int;
TreeType::Pointer tree = TreeType::New();
tree->SetRoot(0);
tree->Add(1,0);
tree->Add(2,0);
tree->Add(3,0);
tree->Add(4,2);
tree->Add(5,2);
tree->Add(6,5);
tree->Add(7,1);
{
std::cout << childIt.
Get() << std::endl;
}
std::cout << std::endl;
{
std::cerr << "Error: The iterator was not of type CHILD." << std::endl;
return EXIT_FAILURE;
}
int oldValue = childIt.
Get();
std::cout << "The node's value is " << oldValue << std::endl;
int newValue = 2;
std::cout <<
"Now, the node's value is " << childIt.
Get() << std::endl;
std::cout <<
"Is this a leaf node? " << childIt.
IsLeaf() << std::endl;
std::cout <<
"Is this the root node? " << childIt.
IsRoot() << std::endl;
std::cout <<
"Does this node have a parent? " << childIt.
HasParent()
<< std::endl;
std::cout << "How many children does this node have? "
std::cout <<
"Does this node have a child 1? " << childIt.
HasChild(1)
<< std::endl;
std::cout << std::endl;
tree->Clear();
delete childItClone;
IteratorCloneType anotherChildItClone = childIt;
std::cout << "ChildTreeIterator:" << std::endl;
{
std::cout << childIt.
Get();
}
std::cout << std::endl;
std::cout << "LeafTreeIterator:" << std::endl;
{
std::cout << leafIt.
Get() << std::endl;
}
std::cout << std::endl;
std::cout << "LevelOrderTreeIterator:" << std::endl;
for (levelIt.GoToBegin(); !levelIt.IsAtEnd(); ++levelIt)
{
std::cout << levelIt.
Get()
<< " ("<< levelIt.GetLevel() << ")"
<< std::endl;
}
std::cout << std::endl;
std::cout << "InOrderTreeIterator:" << std::endl;
{
std::cout << inOrderIt.
Get() << std::endl;
}
std::cout << std::endl;
std::cout << "PreOrderTreeIterator:" << std::endl;
{
std::cout << preOrderIt.
Get() << std::endl;
}
std::cout << std::endl;
std::cout << "PostOrderTreeIterator:" << std::endl;
{
std::cout << postOrderIt.
Get() << std::endl;
}
std::cout << std::endl;
std::cout << "RootTreeIterator:" << std::endl;
for (rootIt.GoToBegin(); !rootIt.IsAtEnd(); ++rootIt)
{
std::cout << rootIt.
Get() << std::endl;
}
std::cout << std::endl;
return EXIT_SUCCESS;
}