以下是一个可以实现上述要求的 C 语言程序:
#include <stdio.h>
void bubble_sort(int *arr, int n, int ascending) {
int i, j, temp;
for (i = 0; i < n - 1; i++) {
for (j = 0; j < n - i - 1; j++) {
if (ascending ? arr[j] > arr[j + 1] : arr[j] < arr[j + 1]) {
temp = arr[j];
arr[j] = arr[j