私はLinkedHashMap
そうのようなもの を持っています
LinkedHashMap <Integer, ArrayList<Integer>> indexToIndecies = new LinkedHashMap <Integer ,ArrayList<Integer>>();
方法がありますpublic int searchGraph(int baseIndex, int searchIndex, int count)
この検索方法のポイントは次のとおりです。誰かbaseIndex
がキーである に入ると、 に到達するのに何回「クリック」する必要があるかを見つけなければなりませんsearchIndex
。キーの値は、関連するインデックスです。したがって、「クリック」はあるキーから別のキーに移動します。したがって、ハッシュマップが次のようになっている場合:
0[2]
1[0, 3]
2[0, 5]
3[0, 2, 4, 5]
4[5]
5[2]
6[3, 4, 5]
7[1, 4]
0 から 5 にするには 2 回のクリックが必要です。
だから、これは私が私の方法のために持っているコードです:
public int searchGraph(int baseIndex, int searchIndex, int count)
{
if (baseIndex == searchIndex)
{
return count;
}
if (searchIndex > indexToIndecies.size()-1){
return -3;
}
else{
for (int i = 0; i < indexToIndecies.get(baseIndex).size(); i++)
{
for (int x = 0; x< indexToIndecies.get(baseIndex).size(); x++){
if (indexToIndecies.get(baseIndex).get(x) == searchIndex){
return count;
}
else{
count++;
}
}
baseIndex = (indexToIndecies.get(baseIndex)).get(i);
}
return count;
}
}
正常に動作し、関連性がある場合は問題ありませんが、関連性がない場合は、それをキャッチする方法がわかりません...どんな助けも大baseIndex
歓迎seachIndex
です。