请使用C++写一个冒泡排序
时间: 2023-05-17 11:02:29 浏览: 88
Sure, here's an example implementation of bubble sort in C:
```
void bubble_sort(int arr[], int n) {
int i, j;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
```
This function takes an array `arr` of length `n` and sorts it in ascending order using the bubble sort algorithm.
阅读全文