linux在unit.c文件中实现一个int型数组排序的函数函数原型如下: void mysort(int *arr,int len);
时间: 2024-02-22 11:57:39 浏览: 30
好的,我可以帮你在Linux系统下实现这个函数。以下是实现代码:
```c
#include <stdio.h>
#include <stdlib.h>
void mysort(int *arr, int len) {
int i, j, temp;
for(i = 0; i < len-1; i++) {
for(j = 0; j < len-i-1; j++) {
if(arr[j] > arr[j+1]) {
temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
int main() {
int arr[] = {5, 2, 8, 3, 1, 9, 4, 6, 7};
int len = sizeof(arr)/sizeof(int);
mysort(arr, len);
int i;
for(i = 0; i < len; i++) {
printf("%d ", arr[i]);
}
printf("\n");
return 0;
}
```
这个程序使用冒泡排序法对传入的整型数组进行排序,从小到大排列。你可以在调用这个函数之前先将要排序的数组传入,然后将数组长度作为第二个参数传入。在这个实现代码中,我在main函数中定义了一个int型数组,将其传入mysort函数中进行排序,然后在控制台输出排序后的结果。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![ts](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)