2
私はムービーディレクターのDVDオブジェクトの配列からバイナリ検索をしようとしていますが、少し問題があります。バイナリ検索を実行すると、監督が映画コレクションに入っていないときのみ、監督はそれがないと言います。私はまだまだ最高の検索ではないので、正しい方向に私を指すための提案があれば感謝します。すべてのバイナリ検索の問題
public int binarySearch(String key) {
int low=0,high=collection.length-1,mid=(low+high)/2;
while (low <= high && collection[mid].getDirector().compareTo(key)!=0) {
if (key.compareTo(collection[mid].getDirector())>0){
low = mid + 1;
}
else {
high = mid - 1;
}
mid=(low+high)/2;
}
if (low>high){
System.out.print("the director is not in your dvd collection");
return -1;
}
else
System.out.print("the movie by director " + collection[mid].getDirector() + " is in index ");
return mid;
}
愚かな質問:これらの「DVD」オブジェクトはムービーディレクターによってソートされていますか? –
DVDオブジェクトはどのようにソートされていますか? –
うわー、私は馬鹿だと感じる。ありがとう、私はそれ以前のタイトルでソートしました –