int[] list = new int[9] { 2, 4, 6, 7, 1, 9, 3, 8, 5 };
int temporarily;
Boolean flag = true ;
int i=1;
int j=1;
for1:
flag =false ;
j = 1;
for2:
if (list[j] < list[j - 1])
{
temporarily = list[j];
list[j] = list[j - 1];
list[j - 1] = temporarily;
flag = true ;
}
if (j<9-i)
{
j += 1;
goto for2;
}
if (i < 8 && flag == true )
{
i += 1;
goto for1;
}
j = 0;
for3:
Console.Write(list[j] + " ");
j++;
if (j < 9)
goto for3;
利用goto,進行氣泡排序
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言