请用c++实现对一维数组[3,4,1,8,0,5,14,10,12,20,23,24,2,17,6,18,9,19]的排序
时间: 2024-05-11 08:15:17 浏览: 21
好的,以下是用c实现对数组[3,4,1,8,0,5,14,10,12,20,23,24,2,17,6,18,9,19]的排序的代码:
```
#include <stdio.h>
int main()
{
int arr[] = {3, 4, 1, 8, 0, 5, 14, 10, 12, 20, 23, 24, 2, 17, 6, 18, 9, 19};
int n = sizeof(arr) / sizeof(arr[0]);
for (int i = 0; i < n-1; i++)
{
for (int 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;
}
}
}
printf("Sorted Array: ");
for (int i = 0; i < n; i++)
{
printf("%d ", arr[i]);
}
return 0;
}
```
运行结果为:
```
Sorted Array: 0 1 2 3 4 5 6 8 9 10 12 14 17 18 19 20 23 24
```
请注意,在实现此排序算法时,我们使用了冒泡排序算法。
阅读全文