예제 #1
0
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
0
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
0
파일: bst.cpp 프로젝트: ds-sww/codebase
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
0
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
0
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
0
파일: ds.cpp 프로젝트: FTUBE/Cpp_Prac
int main(){
  BST binarytree;
  for(int i = 0; i < 128;i++){
  binarytree.add(i);
  }
  //  binarytree.traverse(binarytree.head);
  binarytree.BFS();
}
예제 #7
0
파일: ds.cpp 프로젝트: FTUBE/Cpp_Prac
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();
}
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;
}
//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;
}
예제 #10
0
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;
  }


}