编一函数对数组进行排序(用1个参数指定排序的顺序,默认为升序),然后编写主函数对其进行测试。
#include
//对数组进行排序(第3个参数asc指定排序的顺序,默认为升序)void sort(int *a,int n,___) {
}
void showArray(const int a[],int n) { for (int i=0;i<n;i++) std::cout<<"a["<<i<<"]="<<a[i]<<' '; std::cout<<std::endl;}
int main(void) { int a[]={89,12,78,56,23,45,67,34,45}; const int n=____;
sort(a,n); showArray(a,n); sort(a,n,false); showArray(a,n); sort(a,n,true); showArray(a,n);
return 0;}
输入
无
输出
第1行:从小到大排序后输出数组的所有元素 第2行:从大到小排序后输出数组的所有元素 第3行:从小到大排序后输出数组的所有元素