如下内容内容是关于C#冒泡法排序的内容,应该对码农有一些用途。
int[] myArray = new int[] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };
for( int j=1;j<myArray.Length;j ++ )
{
for(int i=0;i<myArray.Length - 1;i ++)
{
if( myArray[i]>myArray[i+1])
{
int temp = myArray[i];
myArray[i] = myArray[i+1];
myArray[i+1] = temp;
}
}
}
从大到小排序
int[] myArray = new int[] { 10, 8, 3, 5, 6, 7, 4, 6, 9 };
for( int j=1;j<myArray.Length;j ++ )
{
for(int i=0;i<myArray.Length - 1;i ++)
{
if( myArray[i]<myArray[i+1])
{
int temp = myArray[i];
myArray[i] = myArray[i+1];
myArray[i+1] = temp;
}
}
}