本文整理汇总了C++中BST::add方法的典型用法代码示例。如果您正苦于以下问题:C++ BST::add方法的具体用法?C++ BST::add怎么用?C++ BST::add使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BST
的用法示例。
在下文中一共展示了BST::add方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(){
BST<int> bst;
bst.add(2);
bst.add(1);
bst.add(3);
bst.add(13);
bst.add(31);
for (BST<int>::iterator i = bst.begin(); i != bst.end(); ++i){
cout << *i << endl;
}
}
示例2: main
int main() {
BST<int> bst;
bst.add("Alisa", 1, 1000, 400, 50);
bst.add("Sarah", 2, 300, 44, 21);
// Read from file
makeMenuChoice(bst);
system("pause");
return 0;
}
示例3: main
int main()
{
BST test;
int n;
cin >> n;
for (int i=0; i<n; i++)
{
int x;
cin >> x;
test.add(x);
}
cout << test.getmin();
cout << test.getmax();
cout << test.height();
test.prevorder();
test.inorder();
test.postorder();
int x;
cin >> x;
test.del(x);
//test.inorder();
cout << test.size() << endl;
for (int i=0; i<3; i++)
{
cin >> x;
cout << test.rank(x) << endl;
}
}
示例4: addCountry
void addCountry(BST<int> &bst) {
system("CLS");
string country;
int rank, gold, silver, bronze;
char choice = 'a';
cout << "To add a country please insert the necessary information when prompted." << endl << endl;
cout << "Country: ";
cin >> country;
cout << "Rank: ";
cin >> rank;
cout << "Gold Medals earned: ";
cin >> gold;
cout << "Silver Medals earned: ";
cin >> silver;
cout << "Bronze Medals earned: ";
cin >> bronze;
bst.add(country, rank, gold, silver, bronze);
while (toupper(choice) != 'Y' && toupper(choice) != 'N') {
cout << "Would you like to add another?" << endl;
cout << "Y/N: ";
cin >> choice;
}
if (toupper(choice) == 'Y')
addCountry(bst);
else {
cout << "You will now be taken back to the Main Menu." << endl;
system("pause");
mainMenu();
}
}
示例5: main
int main()
{
BST* bst = new BST;
AnalyzeInput* input = new AnalyzeInput;
string cmdString, operation;
int arg1;
while(operation.compare("quit") != 0)
{
cout << "bst> "; getline (cin, cmdString);
input->analyzeCmd(cmdString, operation, arg1);
if(operation.compare("add") == 0) bst->add(arg1);
else if(operation.compare("delete") == 0) bst->numToDelete(arg1);
else if(operation.compare("search") == 0) bst->numToFind(arg1);
else if(operation.compare("inorder") == 0){
bst->print(); cout << endl;}
else if(operation.compare("height") == 0) bst->height();
else if (operation.compare("quit") == 0) bst->quit();
else{ cout << "Error! " << endl; }
}
return 0;
}
示例6: main
int main(){
BST binarytree;
for(int i = 0; i < 128;i++){
binarytree.add(i);
}
// binarytree.traverse(binarytree.head);
binarytree.BFS();
}
示例7: BSTtest
void BSTtest(BST& bst){
int toadd[] = {7,6,43,6,3,5,61,1,6,4,3,5,2,5,2,5,2,5,26,5,6,1,14,4,6,3,1,-1};
int i = 0;
while(toadd[i] != -1){
bst.add(toadd[i]);
i++;
}
bst.DFS();
}
示例8: _tmain
int _tmain(int argc, _TCHAR* argv[])
{
int data =1;
BST *bst = new BST();
while(data!=-1)
{
cin>>data;
bst->add(&(bst->root), data);
}
bst->inorder(&(bst->root));
return 0;
}
示例9: readBST
//build BST by concole input
BST readBST(){
BST t;
int next;
while(cin>>next) {
if(next > 0) {//add
cout<<("Add " + to_string(next) + " : ");
t.add(next);
t.printTree();
} else if(next < 0) {//remove
cout<<("Remove " + to_string(next) + " : ");
t.remove(-next);
t.printTree();
} else {//terminate
vector<int> arr = t.levelOrederArray();
cout<<"Final: ";
for(int i=0; i<t.size; i++) {
cout<<(to_string(arr[i]) + " ");
}
cout<<endl;
return t;
}
}
return t;
}
开发者ID:KHTseng,项目名称:CS6301-Implementation-of-advanced-data-structure-and-algorithms,代码行数:25,代码来源:BST.cpp
示例10: tests
void tests(){
BST<int,std::string> myTree;
myTree.add(1,"hi");
myTree.add(0,"there");
myTree.add(-1,"Friend");
if(myTree.keyExists(1) != true){
std::cout << "ERROR: Key 1 does not exist" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: Key 1 was found" << std::endl;
}
if(myTree.keyExists(-1) != true){
std::cout << "ERROR: Key -1 does not exist" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: Key -1 was found" << std::endl;
}
if(myTree.keyExists(0) != true){
std::cout << "ERROR: Key 0 does not exist" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: Key 0 was found" << std::endl;
}
if(myTree.keyExists(2) == true){
std::cout << "ERROR: Key 2 exists" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: Key 2 was not found" << std::endl;
}
if(myTree.find(1) != "hi"){
std::cout << "ERROR: Key 1 value incorrect" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: Key 1 value correct" << std::endl;
}
if(myTree.find(-1) != "Friend"){
std::cout << "ERROR: Key -1 value incorrect" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: Key -1 value correct" << std::endl;
}
if(myTree.find(0) != "there"){
std::cout << "ERROR: Key 0 value incorrect" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: Key 0 value correct" << std::endl;
}
if(myTree.next(0) != 1){
std::cout << "ERROR: next(0) should be 1" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: next(0) is fine" << std::endl;
}
if(myTree.next(2) != 2){
std::cout << "ERROR: next(2) should be 2" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: next(2) is fine" << std::endl;
}
if(myTree.next(-2) != -1){
std::cout << "ERROR: next(-2) should be -1" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: next(-2) is fine" << std::endl;
}
if(myTree.prev(0) != -1){
std::cout << "ERROR: prev(0) should be -1" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: prev(0) is fine" << std::endl;
}
if(myTree.prev(2) != 1){
std::cout << "ERROR: prev(2) should be 1" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: prev(2) is fine" << std::endl;
}
if(myTree.prev(-2) != -2){
std::cout << "ERROR: prev(-2) should be -2" << std::endl;
exit(1);
} else {
std::cout << "SUCCESS: prev(-2) is fine" << std::endl;
}
}