オーケーで、私は整数の選択ソートを行うには、このコードを使用してきた:C#の選択ソート列
public void selectSort(int [] arr)
{
//pos_min is short for position of min
int pos_min,temp;
for (int i=0; i < arr.Length-1; i++)
{
pos_min = i; //set pos_min to the current index of array
for (int j=i+1; j < arr.Length; j++)
{
if (arr[j] < arr[pos_min])
{
//pos_min will keep track of the index that min is in, this is needed when a swap happens
pos_min = j;
}
}
//if pos_min no longer equals i than a smaller value must have been found, so a swap must occur
if (pos_min != i)
{
temp = arr[i];
arr[i] = arr[pos_min];
arr[pos_min] = temp;
}
}
}
が、今私の代わりに文字列リストに同じアルゴリズムを実行したいです。
これはどのように達成できますか?それは本当に扱いにくいと感じ、あなたは別の文字列の複数の文字を比較するために追加のループが必要なようです..?
私はたくさん試しましたが、何か役に立つものを考え出すことができませんでした。 :/
注: 私が知っている選択ソートはあまり効率的ではありません。これは学習目的のためのものです。私はすでにC#の一部である代わりのアルゴリズムやクラスを探していません。 ;)
しかし、文字列にも '<', '> '、' == '、'!= 'などの演算子を使用できます。文字をループする必要はありません。 –
あなたが探しているものは本当にわかりません。組み込みの文字列比較を使用できない場合は、文字を比較するためのfor-loopを書く必要があります。 –