11.3中一段伪代码怎样转换为C#代码
void qsort3(l,u)
if (l >= u)
return
t = x[1];i = 1;j = u + 1;
loop
do i++ while i <= u && array[i] < t
do j-- while array[j] > t
if i > j
break;
Swap(ref array[i], ref array[j]);
Swap(ref l, ref j);
qsort3(l, j - 1);
qsort3(j + 1, u);c#编程快速排序算法
void qsort3(l,u)
if (l >= u)
return
t = x[1];i = 1;j = u + 1;
loop
do i++ while i <= u && array[i] < t
do j-- while array[j] > t
if i > j
break;
Swap(ref array[i], ref array[j]);
Swap(ref l, ref j);
qsort3(l, j - 1);
qsort3(j + 1, u);c#编程快速排序算法
{
if (l >= u)
return;
t = x[1];i = 1;j = u + 1;
while (true)
{
do { i++; } while (i <= u && array[i] < t)
do { j--; } while (array[j] > t)
if (i > j)
break;
Swap(ref array[i], ref array[j]);
}
Swap(ref l, ref j);
qsort3(l, j - 1);
qsort3(j + 1, u);
}
int[] x;
int[] array; void qsort3(int l, int u)
{
int i,j,t; if (l >= u)
return;
t = x[1];i = 1;j = u + 1;
while(true)
{
do
{
i++;
}
while (i <= u && array[i] < t); do
{
j--;
}
while (array[j] > t); if (i > j)
break; Swap(ref array[i], ref array[j]);
}
Swap(ref l, ref j); qsort3(l, j - 1);
qsort3(j + 1, u);
} private void Swap(ref int i, ref int j)
{
int t = i;
i = j;
j = t;
}
public void QuickSort(int startIndex, int endIndex)
{
if (startIndex >= endIndex)
{
return;
}
int m = startIndex;
for (int i = startIndex + 1; i <= endIndex; i++)
{
if (array[i] < array[startIndex])
{
Swap(ref array[++m], ref array[i]);//++指向小元素的新位置
}
}
Swap(ref array[startIndex], ref array[m]);
QuickSort(startIndex, m - 1);
QuickSort(m + 1, endIndex);
}