0

私はデータベース内の正確な値を検索する実用的な検索機能を持っていますが、私の目標は、保存されたデータのデータベース内の部分文字列を検索することです.ツリーを介した検索が短くなり、一部の部分文字列が見つかり、他の部分文字列が見つからないことがわかりますか? なんで?

  bool contains(const Comparable & key, BinaryNode *leaf)
  {
    //cout << "containsing... for: " << key << endl;
    if(leaf != NULL)
    { 
     //std::string Data = leaf->element;

    //cout << "check passed for contains!" << endl;
    if(leaf->element.find(key) != std::string::npos)
    {
       //std::cout << "Found->" << key << "!" << endl;
       return true;
    }
    else if(key >= leaf->element)
    {
     // cout << "key->" << key << "is less than leaf->" <<leaf->element << endl;
      if(leaf->left != NULL)
       return contains(key, leaf->left);
      else
       return false;
    }
    else if(key < leaf->element)
    { 
      //cout << "key->" << key << "is greater than leaf->" <<leaf->element << endl;
      if(leaf->right != NULL)
       return contains(key, leaf->right);
      else
       return false;
    }
    else
      return false;
  }
 else 
  return false;  

} 
4

1 に答える 1