131-5-1计算机程序计-函数(赵老师).ppt

131-5-1计算机程序计-函数(赵老师).ppt

* 例5-5编写用于对整型数组排序的函数 // Example 5-5: 交换排序 #include iostream using namespace std; void bubble_up(int list[], int count) { for(int i=0; icount; i=i+1) for(int j=count-1; ji; j=j-1) if(list[j-1]list[j]) { int tmp = list[j-1]; list[j-1] = list[j]; list[j] = tmp; } } * //测试冒泡法排序的主程序 int main() { int i; int array[16]= { 503, 87, 512, 61, 908, 170, 897, 275, 653, 426, 154, 509, 612, 677, 765, 703 }; cout 原数组是: endl; for(i=0; i16; i++) cout array [i] ; coutendl; * bubble_up(array, 5); // 函数调用 cout 对数组前5项进行排序后的结果是: endl; for(i=0; i16; i++) cout array [i]

文档评论(0)

1亿VIP精品文档

相关文档