快速排序代码(2)
来源:未知 责任编辑:责任编辑 发表时间:2015-09-17 09:43 点击:次
Sort(numbers,left,i - 1);
Sort(numbers,j + 1,right);
}
}
/// <summary>
/// 交换元素值
/// </summary>
/// <param name="numbers">数组</param>
/// <param name="i">当前左边索引</param>
/// <param name="j">当前右边索引</param>
private static void Swap(int[] numbers,int i,int j)
{
int number = numbers[i];
numbers[i] = numbers[j];
numbers[j] = number;
}
public static void Main()
{
int[] arr = { 6,5,2,9,7,4,0,-1,-4,-2,3,2,0,9 };
Sort(arr, 0, arr.Length-1);
StringBuilder temp = new StringBuilder();
for (int i = 0; i <= arr.Length-1; i++)
{
temp.Append(arr[i].ToString()+",");
}
Console.WriteLine(temp.ToString().Substring(0, temp.Length-1));
Console.ReadLine();
}
}
}
作者 张银
相关新闻>>
- 发表评论
-
- 最新评论 更多>>