From f02d1870ec52ddced24373c9f126d547499b6216 Mon Sep 17 00:00:00 2001 From: Liuhua Date: Sun, 3 Dec 2023 02:40:18 +0000 Subject: [PATCH] =?UTF-8?q?CI=E6=B5=8B=E8=AF=95=E5=8D=95=EF=BC=8C=E8=AF=B7?= =?UTF-8?q?=E5=8B=BF=E5=90=88=E5=85=A5!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Liuhua --- test1203.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 test1203.c diff --git a/test1203.c b/test1203.c new file mode 100644 index 00000000..3b3cf745 --- /dev/null +++ b/test1203.c @@ -0,0 +1,26 @@ +#include + +void bubbleSort(int arr[], int n) { + int i, j, temp; + for (i = 0; i < n-1; i++) { + for (j = 0; j < n-i-1; j++) { + if (arr[j] > arr[j+1]) { + // 交换arr[j]和arr[j+1] + temp = arr[j]; + arr[j] = arr[j+1]; + arr[j+1] = temp; + } + } + } +} + +int main() { + int arr[] = {64, 34, 25, 12, 22, 11, 90}; + int n = sizeof(arr)/sizeof(arr[0]); + bubbleSort(arr, n); + printf("Sorted array: "); + for (int i=0; i < n; i++) { + printf("%d ", arr[i]); + } + return 0; +} \ No newline at end of file -- Gitee