问答题
采用冒泡法对数组a中的整数由小到大进行排序。
#include < iostream.h >
void sort(int b[], int n)
{int i, j =0, t;
for(i= 1; i <n; i++)
{for(j =0; ______; j ++ )
{if(b[j] >b[j+1])
{t=b[j]; ______; b[j+1] =t;}
}
}
}
void main()
{int a[] ={3,2,7,1,19,6,2,8};
int i ;
for(i =0; i <8; i ++)
cout << a[i] <<" ";
cout << endl;
sort(a,8);
for(i =0; i <8; i ++ )
cout << a[i] <<" ";
cout << endl;
}
【参考答案】
j<n-i b[j]=b[j+1]