C#编写的8种排序方法
--------------------编程问答-------------------- 我一般是不看链接的 --------------------编程问答--------------------不好意思,,编辑太慢了,修改不了了,只有贴下面
static public void fastsort(int[] array, int begin,int end) //快速排序
{
if (begin < 0 || end < 0 || begin >end)
return;
int left = begin, right = end, temp; //经典的快排
temp = array[left];
while (right != left)
{
while (temp < array[right] && right>left)
right--;
if (right > left)
{
array[left] = array[right];
left++;
}
while (temp > array[left] && right > left)
left++;
if (right > left)
{
array[right] = array[left];
right--;
}
}
array[right] = temp;
fastsort(array, right + 1, end);
fastsort(array, begin, right-1);
}
static public void selectsort(int[] array, int length) //选择排序
{
int i=0, j, min,temp_array,temp;
while (i < length - 1)
{
min = array[i];
temp = i;
for (j = i+1; j < length; j++)
{
if (array[j] < min)
{
min = array[j];
temp = j;
}
}
temp_array = array[i];
array[i] = array[temp];
array[temp] = temp_array;
i++;
}
}
--------------------编程问答-------------------- 刚做个网站想炫耀一下吧?
你那个网站上已经有不和谐文章了,很快就有网警邀请你去喝茶了。
再往后,可能就是抱服务器了。 --------------------编程问答--------------------
呵呵,哪里不和谐了? --------------------编程问答-------------------- 看看
文章排版有点乱 --------------------编程问答--------------------
我去看了下,没看到不和谐的文章,在哪页啊。我好请他喝cf --------------------编程问答-------------------- 震惊!肉价下跌的真正原因竟是高房价绞杀 --------------------编程问答--------------------
那个不是吧,,那个是凤凰网上的呢~~ --------------------编程问答-------------------- 大家帮忙顶下,讨论讨论啊~ --------------------编程问答-------------------- 震惊!肉价下跌的真正原因竟是高房价绞杀 --------------------编程问答-------------------- JF 不错 挺好的 ,有时间学习一下. --------------------编程问答-------------------- 挺好的, --------------------编程问答--------------------
谢谢,,我现在缺少支持,,哎~~~ --------------------编程问答-------------------- 一起丰富下吧~~ --------------------编程问答-------------------- 最后一次邀请 --------------------编程问答-------------------- 又一个瞎折腾的。 --------------------编程问答--------------------
啥意思:? --------------------编程问答--------------------
哈哈哈 --------------------编程问答-------------------- mark --------------------编程问答-------------------- 震惊!肉价下跌的真正原因竟是高房价绞杀 --------------------编程问答-------------------- --------------------编程问答-------------------- 从七楼开始就歪楼了。 --------------------编程问答-------------------- static void Main(string[] args)
{
int[] test7 = { 21, 13, 321, 231, 43, 7, 65, 18, 48, 6 };
heapsort(test7, 0, 9); //堆排序
foreach (int a in test7)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
int[] test6 = { 21, 13, 321, 231, 43, 7, 65, 18, 48, 6 };
radixsort(test6, 0, 9, 2); //基数排序(第4个参数是数组中最大数的10的最大次瞑)
foreach (int a in test6)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
int[] test0 = { 21, 13, 321, 231, 43, 7, 65, 18, 48, 6 };
insertsort(test0, 10); //插入排序
foreach (int a in test0)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
int[] test1 = { 21, 13,321, 231, 43, 7, 65, 18, 48, 6 };
newinsertsort(test1, 10); //折半插入排序
foreach (int a in test1)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
int[] test2 = { 21, 13,321, 231, 43, 7, 65, 18, 48, 6 };
shellsort(test2, 10); //希尔排序
foreach (int a in test2)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
int[] test3 = { 21, 13, 321, 231, 43, 7, 65, 18, 48, 6 };
paopaosort(test3, 10); //冒泡排序
foreach (int a in test3)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
int[] test4 = { 21, 13, 321, 231, 43, 7, 65, 18, 48, 6 };
fastsort(test4, 0, 9); //快速排序
foreach (int a in test4)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
int[] test5 = { 21, 13, 321, 231, 43, 7, 65, 18, 48, 6 };
selectsort(test5, 10); //选择排序
foreach (int a in test5)
Console.Write(a.ToString().PadRight(4));
Console.WriteLine();
Console.Read();
}
--------------------编程问答-------------------- 帮顶接分 --------------------编程问答-------------------- 有不和谐文章吗 我去瞄瞄 --------------------编程问答-------------------- 可以参考参考,那个网站也没啥问题啊~~~ --------------------编程问答-------------------- 接分。
补充:.NET技术 , C#