training

Code I wrote during training
git clone git://git.bitsmanent.org/training
Log | Files | Refs | README

binarySearchTree.c (464B)


      1 /* Exercise 12.23 */
      2 
      3 Tree binarySearchTree( Tree *treePtr, int value )
      4 {  
      5    Tree *retp = treePtr;
      6 
      7    if( retp != NULL ) {
      8       if( (retp->left != NULL && retp->data == value) ||
      9           (retp->right != NULL && retp->data == value)
     10       ) return retp;
     11 
     12       if( retp->data > value )
     13          return binarySearchTree( retp->left, value );
     14       else
     15          return binarySearchTree( retp->rightr, value );
     16    }
     17  
     18    return NULL;
     19 
     20 } /* eof searchTree() */
     21