コード例 #1
0
ファイル: BSTSort.cpp プロジェクト: th58/Data_Structures
int bstSort(std::vector<int> numVec)
{
  BinarySearchTree* bst = new BinarySearchTree();

  for(std::vector<int>::iterator it = numVec.begin(); it != numVec.end(); ++it)
    bst->insert(new Node(*it));

  int size;
  int index;
  
  numVec.clear();


  bst->inorder(numVec);
  size = numVec.size();
  index = (size - 1)/2;

  bst->empty();
  delete bst;
  if(size % 2 == 0)
    {
      int mean = (numVec.at(index) + numVec.at(index + 1)/2);
      return mean;
    }

  int mean = numVec.at(index);
  return mean;
}
コード例 #2
0
ファイル: test0.cpp プロジェクト: GHScan/DailyProjects
void basic_test()
{
    BinarySearchTree<int> tree;
    for (int i = 0; i < 15; i += 3) tree.insert(i);

    assert(tree.size() == 5);
    assert(tree.search(3));
    assert(tree.search(12));
    assert(!tree.search(10));
    assert(!tree.erase(8));
    assert(tree.search(9));
    assert(tree.erase(9));
    assert(!tree.erase(9));
    assert(tree.size() == 4);
    assert(!tree.insert(3));
    assert(tree.insert(13));
    assert(tree.size() == 5);
    assert(tree.erase(13));
    assert(tree.erase(12));
    assert(tree.erase(6));
    assert(tree.erase(3));
    assert(tree.erase(0));
    assert(tree.empty());
}