e12-01.cpp
来自「游戏开发数据结构Data Structures for Game Program」· C++ 代码 · 共 54 行
CPP
54 行
// =======================================================
// Chapter 12, Example 1
// Playing around with Binary Trees
// =======================================================
#include <iostream.h>
#include <stdio.h>
#include "BinaryTree.h"
void main()
{
BinaryTree<int>* root = 0;
BinaryTree<int>* itr = 0;
// create a root node.
root = new BinaryTree<int>;
root->m_data = 1;
// create left and right children.
root->m_left = new BinaryTree<int>;
root->m_left->m_data = 2;
root->m_left->m_parent = root;
root->m_right = new BinaryTree<int>;
root->m_right->m_data = 3;
root->m_right->m_parent = root;
// use the iterator to go down and create left and right
// nodes on the left child of the root.
itr = root;
itr = itr->m_left;
itr->m_left = new BinaryTree<int>;
itr->m_left->m_data = 4;
itr->m_left->m_parent = itr;
itr->m_right = new BinaryTree<int>;
itr->m_right->m_data = 5;
itr->m_right->m_parent = itr;
// go back up
itr = itr->m_parent;
// use the iterator to go down and create left and right
// nodes on the right child of the root.
itr = itr->m_right;
itr->m_left = new BinaryTree<int>;
itr->m_left->m_data = 6;
itr->m_left->m_parent = itr;
itr->m_right = new BinaryTree<int>;
itr->m_right->m_data = 7;
itr->m_right->m_parent = itr;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?