なぜこのコードが間違っていますか?私は紙の上で、何が間違っていないことをトレースしているクイックソートのピボットとしての最初の要素
:クイックソートでは、私は、ピボットとして最初の要素を取り上げています。
private void QuickSort(ref int [] S ,int l,int h)
{
//partioning
int pivot_index = l;
int j = 0;
int temp = 0;
for(int i=l+1;i<=h;i++)
if (S[pivot_index] > S[i])
{
j++;
temp = S[i];
S[i] = S[j];
S[j] = temp;
}
pivot_index = j;
temp = S[l];
S[l] = S[j];
S[j] = temp;
//end partioning
if (l < h && pivot_index>l && pivot_index<h)
{
QuickSort(ref S, l, pivot_index - 1);
QuickSort(ref S, pivot_index + 1, h);
}
}
はここに私のメインです:
int[] List = get_input(textBox1.Text, ref n);
//
QuickSort(ref List, 0, n-1);
なぜあなたは参照によって配列を渡していますか?配列はすでに参照型です。 –
あなたの表記に感謝 – PasJ
純粋なC#コードではありませんか?なぜC++タグですか? –