main.cpp
来自「数据结构与程序设计教材源码 数据结构与程序设计教材源码」· C++ 代码 · 共 75 行
CPP
75 行
#include "../../C/UTILITY.H"
#include "BNODE.H"
#include "BTREE.H"
#include "BNODE.CPP"
#include "BTREE.CPP"
int get_int()
{
char c;
int ans = 0, sign = 1;
do {
cin.get(c);
if (c == '-') sign = -1;
} while (c < '0' || c > '9');
while (c >= '0' && c <= '9') {
ans = 10 * ans + c - '0';
cin.get(c);
}
return ans * sign;
}
char get_command()
{
char c, d;
cout << "Select command (H for help) and press <Enter>:";
while (1) {
do {
cin.get(c);
} while (c == '\n');
do {
cin.get(d);
} while (d != '\n');
c = tolower(c);
if (c == 'r' || c == 'i' || c == 'c' ||
c == 'q' || c == 'p') {
return c;
}
cout << "Please enter a valid command or H for help:";
cout << "\n\t[R]emove entry\t[P]rint tree\n"
<< "\t[I]nsert entry\n"
<< "\t[Q]uit.\n";
}
}
int do_command(char c, B_tree<int, 4> &test_tree)
{
int x;
switch (c) {
case 'r':
cout << "Enter integer to remove:" << flush;
x = get_int();
if (test_tree.remove(x) != success) cout << "Not found!\n";
break;
case 'i':
cout << "Enter new integer to insert:";
x = get_int();
test_tree.insert(x);
break;
case 'p':
test_tree.print();
break;
case 'q':
cout << "B-tree demonstration finished.\n";
return 0;
}
return 1;
}
main()
{
B_tree<int, 4> test_tree;
while (do_command(get_command(), test_tree));
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?