using
System;
using
System.Collections.Generic;
using
System.Text;
namespace
ConsoleApplication1
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
{
class Program
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
static void Main(string[] args)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
int[] iarrary = new int[]
{1,5,13,6,10,55,99,2,87,12,34,75,33,47};
//mpsort(iarrary);
// xzsort(iarrary);
crsort(iarrary);
for (int n = 0; n < iarrary.Length; n++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
Console.WriteLine("{0}",iarrary[n]);
}
Console.Read();
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static void mpsort(int [] list)//冒泡排序
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int i, j, temp;
bool exchange;
for (i = 1; i < list.Length; i++)//最多做list.Length-1趟排序
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
exchange = false;
for (j = 0; j < list.Length-i;j++ )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if(list[j]>list[j+1])
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp = list[j];
list[j] = list[j + 1];
list[j + 1] = temp;
exchange = true;
}
}
if (!exchange)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
break;
}
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static void xzsort(int[] list)//选择排序
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int i,j,temp,min;
for (i = 0; i < list.Length; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
min = i;
for (j = i + 1; j < list.Length;j++ )
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
if (list[min] > list[j])
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
min = j;
}
}
temp = list[min];
list[min] = list[i];
list[i] = temp;
}
}
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
public static void crsort(int[] list)//插入排序
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
int i,j,temp;
for (i = 1; i < list.Length; i++)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
temp = list[i];
j = i;
while((j > 0)&&(list[j-1]>temp))
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
{
list[j]=list[j-1];
--j;
}
list[j]=temp;
}
}
}
}
转载于:https://www.cnblogs.com/xiaobeisong/archive/2008/07/08/1238198.html