binarysearchtree.cpp

来自「这是数据结构、算法与应用-C++语言描述的代码」· C++ 代码 · 共 56 行

CPP
56
字号
// test binary search tree class

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

using namespace std;


int main(void)
{
   binarySearchTree<int, char> y;
   y.insert(pair<int, char>(1, 'a'));
   y.insert(pair<int, char>(6, 'c'));
   y.insert(pair<int, char>(4, 'b'));
   y.insert(pair<int, char>(8, 'd'));
   cout << "Tree size is " << y.size() << endl;
   cout << "Elements in ascending order are" << endl;
   y.ascend();

   pair<const int, char> *s = y.find(4);
   cout << "Search for 4 succeeds " << endl;
   cout << s->first << ' ' << s->second << endl;
   y.erase(4);
   cout << "4 deleted " << endl;
   cout << "Tree size is " << y.size() << endl;
   cout << "Elements in ascending order are" << endl;
   y.ascend();

   s = y.find(8);
   cout << "Search for 8 succeeds " << endl;
   cout << s->first << ' ' << s->second << endl;
   y.erase(8);
   cout << "8 deleted " << endl;
   cout << "Tree size is " << y.size() << endl;
   cout << "Elements in ascending order are" << endl;
   y.ascend();

   s = y.find(6);
   cout << "Search for 6 succeeds " << endl;
   cout << s->first << ' ' << s->second << endl;
   y.erase(6);
   cout << "6 deleted " << endl;
   cout << "Tree size is " << y.size() << endl;
   cout << "Elements in ascending order are" << endl;
   y.ascend();

   s = y.find(1);
   cout << "Search for 1 succeeds " << endl;
   cout << s->first << ' ' << s->second << endl;
   y.erase(1);
   cout << "1 deleted " << endl;
   cout << "Tree size is " << y.size() << endl;
   cout << "Elements in ascending order are" << endl;
   y.ascend();
}

⌨️ 快捷键说明

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