冒泡
冒泡排序
Int [] shuzu = new int [10];
For ( int i= 0;i <10 ; i ++)
{
For (int a = i ; a<10-1;a ++)
{
If (shuzu [i ]>shuzu [a +1])
{
Int zhong = ahuzu [i];
Shuzu[i]= shuzu [j +1];
Shuzu [j+1]= zhong ;
}
}
遍历数组
Foreach ( int a in shuzu )
{
Console.writeline(a );
}
Console .readline();
冒泡理论:
-
两层循环
外层:循环趟数。 N- 1
里层:两两比较的次数。 N -趟数
Int []a = new int [8];
For ( int i = 1; i <= 7 ; i ++)
{
For (int j = 1; j <= 8 - i ; j ++)
{
If (a [j] < a [j - 1])
{
Int t = a [j];
a [j]= a [j - 1];
t = a [j - 1 ];
}
}
}