C++学习--点滴记录007( 二 )

<< "a = " << a << endl;cout << "b = " << b << endl;}int main(){test01();system("pause");return 0;}
7.8 指针、数组、函数
案例描述: 封装一个函数,利用冒泡排序,实现对整型数组的升序排序
示例:
#include using namespace std;//冒泡排序函数void bubbleSort(int* arr, int len) {for (int i = 0; i < len - 1; i++){for (int j = 0; j < len - 1 - i; j++){if (arr[j] > arr[j + 1]){int temp = arr[j];arr[j] = arr[j + 1];arr[j + 1] = temp;}}}}//打印数组函数void printArray(int arr[], int len){for (int i = 0; i < len; i++){cout << arr[i] << " ";}cout << endl;}void test01(){int arr[10] = { 1,3,9,5,7,2,4,8,6,2 };int len = sizeof(arr) / sizeof(int);bubbleSort(arr, len);printArray(arr, len);}int main(){test01();system("pause");return 0;}
希望本文对大家有帮助,上文若有不妥之处,欢迎指正