⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e12-01.cpp

📁 游戏开发数据结构Data Structures for Game Programmers
💻 CPP
字号:
// =======================================================
//  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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -