#include <iostream>
using namespace std;
#include <string.h>
void bubbleSort(int* a, int len) {
for (int i = 0; i < len - 1; i++)
{
for (int j = 0; j < len - 1 - i; j++) {
if (a[j] > a[j + 1]) {
int temp = a[j + 1];
a[j + 1] = a[j];
a[j] = temp;
}
}
}
}
void printa(int* a, int len) {
cout << "排序后的数组" << endl;
for (int i = 0; i < len; i++) {
cout << a[i] << endl;
}
}
int main() {
int a[] = { 1,2,3,8,7,9,4 };
int len = sizeof(a) / sizeof(a[0]);
bubbleSort(a,len);
printa(a,len);
system("pause");
return 0;
}
【C++】指针进行数组冒泡排序
最新推荐文章于 2023-05-14 21:04:43 发布