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

📄 testprogbinarysearchtree.cpp

📁 C++编成数据结构与程序设计方法 D.S.Malk编著
💻 CPP
字号:

#include <iostream>
#include "binarySearchTree.h"

using namespace std;

int main()
{
    bSearchTreeType<int>  treeRoot;
	
    int num;

    cout << "Enter numbers ending with -999." << endl;
    cin >> num;

    while (num != -999)
    {
        treeRoot.insert(num);
        cin >> num;
    }

    cout << endl << "Tree nodes in inorder sequence: ";
    treeRoot.inorderTraversal();

    cout << endl << "Tree nodes in preorder sequence: ";
    treeRoot.preorderTraversal();

    cout << endl << "Tree nodes in postorder sequence: ";
    treeRoot.postorderTraversal();
    cout << endl;

    cout << "Tree Height: " << treeRoot.treeHeight()
         << endl;
    cout << "Number of Nodes: "
         << treeRoot.treeNodeCount() << endl;
    cout << "Number or Leaves: "
         << treeRoot.treeLeavesCount() << endl;
    cout << endl;

    cout << "Enter the item to be searched: ";
    cin >> num;
    cout << endl;

    if (treeRoot.search(num))
        cout << num << " is in the binary tree." << endl;
    else
        cout << num << " is not in the tree." << endl;

    cout << "Enter the item to be deleted: ";
    cin >> num;
    cout << endl;

    treeRoot.deleteNode(num);

    cout << endl << "**** After the delete operation.****"
         << endl;
    cout << "Tree nodes in inorder sequence: ";
    treeRoot.inorderTraversal();
    cout << endl << "Tree nodes in preorder sequence: ";
    treeRoot.preorderTraversal();

    cout << endl << "Tree nodes in postorder sequence: ";
    treeRoot.postorderTraversal();
    cout << endl;

    return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -