Posted By

DrPepper on 09/19/11


Tagged


Versions (?)

[CISP 430] Binary Tree Search


 / Published in: C++
 

URL: http://en.wikipedia.org/wiki/Binary_search_tree

This is about binary search

  1. bool BinarySearchTree::search(int val)
  2. {
  3. Node *next = this->root();
  4.  
  5. while (next != NULL)
  6. {
  7.  
  8. // PREORDER
  9. if (val == next->value())
  10. { return true; }
  11.  
  12. // POSTORDER
  13. else if (val < next->value())
  14. { next = next->left(); }
  15.  
  16. // IN-ORDER
  17. else
  18. { next = next->right(); }
  19. }
  20.  
  21. //not found
  22. return false;
  23. }

Report this snippet  

You need to login to post a comment.