c++程序—冒泡排序法(函数、指针)
#include<iostream> using namespace std; void bubbleArr(int *arr,int len) { for (int i = 0; i < len - 1; i++) { for (int j = 0; j < len - i - 1; j++) { if (arr[j] > arr[j + 1]) { int temp = arr[j]; arr[j] = arr[j + 1]; arr[j + 1] = temp; } } } } void outputArr(int *arr,int len) { for (int i = 0; i < len; i++) cout << arr[i] << " "; cout << endl; } int main() { int arr[] = { 3,6,7,5,1,0,9,8,4,2 }; int len = sizeof(arr) / sizeof(arr[0]); cout << "原来数组为:" << endl; outputArr(arr, len); bubbleArr(arr, len); cout << "冒泡排序后的数组为:" << endl; outputArr(arr, len); system("pause"); return 0; }