dbinarysearchtree.cpp
来自「这是数据结构、算法与应用-C++语言描述的代码」· C++ 代码 · 共 77 行
CPP
77 行
// test binary search tree with duplicates class
#include <iostream>
#include "dBinarySearchTree.h"
using namespace std;
int main(void)
{
dBinarySearchTree<int, char> y;
y.insert(pair<int, char>(1, 'a'));
y.insert(pair<int, char>(6, 'f'));
y.insert(pair<int, char>(3, 'c'));
y.insert(pair<int, char>(4, 'e'));
y.insert(pair<int, char>(1, 'b'));
y.insert(pair<int, char>(6, 'g'));
y.insert(pair<int, char>(3, 'd'));
cout << "Tree size is " << y.size() << endl;
cout << "Elements in ascending order are" << endl;
y.ascend();
pair<const int, char> *s = y.find(3);
cout << "Search for 3 succeeds " << endl;
cout << s->first << ' ' << s->second << endl;
y.erase(3);
cout << "3 deleted " << endl;
cout << "Tree size is " << y.size() << endl;
cout << "Elements in ascending order are" << endl;
y.ascend();
s = y.find(3);
cout << "Search for 3 succeeds " << endl;
cout << s->first << ' ' << s->second << endl;
y.erase(3);
cout << "3 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();
s = y.find(8);
if (s == NULL)
cout << "Search for 8 fails " << 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();
y.insert(pair<int, char>(1, 'a'));
y.insert(pair<int, char>(6, 'f'));
y.insert(pair<int, char>(3, 'c'));
y.insert(pair<int, char>(4, 'e'));
y.insert(pair<int, char>(1, 'b'));
y.insert(pair<int, char>(6, 'g'));
y.insert(pair<int, char>(3, 'd'));
cout << "Tree size is " << y.size() << endl;
cout << "Elements in ascending order are" << endl;
y.ascend();
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?