当前位置: 首页>>代码示例>>C++>>正文


C++ BinaryTree::getSize方法代码示例

本文整理汇总了C++中BinaryTree::getSize方法的典型用法代码示例。如果您正苦于以下问题:C++ BinaryTree::getSize方法的具体用法?C++ BinaryTree::getSize怎么用?C++ BinaryTree::getSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BinaryTree的用法示例。


在下文中一共展示了BinaryTree::getSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: tryTree

void NodeController :: tryTree()
{
    BinaryTree<int> sampleTree;
    sampleTree.insert(7);
    sampleTree.insert(5);
    cout << "The tree is this big: " << sampleTree.getSize() << endl;
    sampleTree.insert(213);
    sampleTree.insert(-123);
    cout << "The tree is this big: " << sampleTree.getSize() << endl;
    sampleTree.insert(5);
    cout << "The tree is this big: " << sampleTree.getSize() << endl;
    sampleTree.insert(123124);
    sampleTree.insert(0);
    cout << "The tree is this big: " << sampleTree.getSize() << endl;
    cout << "The in order traversal" << endl;
    sampleTree.inOrderTraversal(sampleTree.getRoot());
    cout << endl;
    
    cout << "The pre order traversal" << endl;
    sampleTree.preOrderTraversal(sampleTree.getRoot());
    cout << endl;
    
    cout << "The post order traversal" << endl;
    sampleTree.postOrderTraversal(sampleTree.getRoot());
    cout << endl;
    
}
开发者ID:Roboteacherutah,项目名称:ScottNodeProject,代码行数:27,代码来源:NodeController.cpp

示例2: main

int main()
{
  BinaryTree<int> empty;
  BinaryTree<int> complete = generateCompleteTree(30);
  BinaryTree<int> list = generateLinkedList(100);

  // empty tree is empty
  assert(empty.isEmpty());

  // size of complete tree
  assert(complete.getSize() == 31);

  // size of list
  assert(list.getSize() == 100);


  // depth of complete tree
  assert(complete.getDepth() == 4);

  // depth of list
  assert(list.getDepth() == 99);


  typedef BinaryTree<int>::NodeDeque traversal_type;

  // root is at the front of a preorder traversal
  traversal_type pre;
  complete.preorder(pre, complete.getRoot());
  assert(pre.front() == complete.getRoot());

  // root is at the end of a postorder traversal
  traversal_type post;
  complete.postorder(post, complete.getRoot());
  assert(post.back() == complete.getRoot());

  // root is in the middle of an inorder traversal
  traversal_type in;
  complete.inorder(in, complete.getRoot());
  assert(in.at(in.size()/2) == complete.getRoot());


  // traversals should contain all nodes of the tree
  assert(pre.size() == complete.getSize());
  assert(post.size() == complete.getSize());
  assert(in.size() == complete.getSize());

  typedef BinaryTree<int>::NodePtr iterator;
  const int query_value = 22;
  
  // 22 should be in the list and complete tree
  iterator complete_query = complete.simpleSearch(query_value);
  iterator list_query = list.simpleSearch(query_value);
  iterator empty_query = empty.simpleSearch(query_value);

  assert(complete_query != NULL);
  assert(list_query != NULL);
  assert(empty_query == NULL);
  

  // test copy ctor and assignment operator
  BinaryTree<int> copied(complete);
  BinaryTree<int> assigned;
  assigned = complete;

  // should have same size
  assert(copied.getSize() == complete.getSize());
  assert(assigned.getSize() == complete.getSize());

  // should still have 22
  iterator copy_query = copied.simpleSearch(query_value);
  iterator assign_query = assigned.simpleSearch(query_value);

  assert(copy_query != NULL);
  assert(assign_query != NULL);

  std::cout << "Passed!" << std::endl;

  return 0;
}
开发者ID:brucezheng,项目名称:CSCE221,代码行数:79,代码来源:correctness.cpp


注:本文中的BinaryTree::getSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。