#include <stdio.h> int p_sort(int *s); int q_sort(int *s,int low,int high); int sort(int *s,int low,int high); int p_sort(int *s){ int i=0; for(i=0;i<10;i++){ printf("%d ",s[i]); } printf("\n"); } int q_sort(int *s,int low,int high){ if(low<high){ int temp=sort(s,low,high); sort(s,low,temp-1); sort(s,temp+1,high); } return 0; } int sort(int *s,int low,int high){ int pivot=s[low]; while(low<high){ while(low<high&&s[high]>=pivot) --high; s[low]=s[high]; while(low<high&&s[low]<=pivot) ++low; s[high]=s[low]; } s[low]=pivot; return low; } int main(int argc, const char *argv[]){ //int s[10]={10,2,3,4,5,6,7,9,12,8}; int s[10]={4,9,8,7,2,3,5,6,50,45}; q_sort(s,0,9); p_sort(s); return 0; } 帮我看看这段代码哪错了
时间: 2024-04-16 10:25:18 浏览: 23
在你提供的代码中,`p_sort`函数声明的返回类型是`int`,但是函数内部没有返回语句。根据函数声明,`p_sort`应该返回一个整数值。
如果你只是想在`p_sort`函数中打印数组元素而不返回任何值,可以将函数的返回类型改为`void`。这样,函数就不需要返回语句了。
修正后的代码如下所示:
```c
#include <stdio.h>
void p_sort(int *s);
int q_sort(int *s, int low, int high);
int sort(int *s, int low, int high);
void p_sort(int *s) {
int i = 0;
for (i = 0; i < 10; i++) {
printf("%d ", s[i]);
}
printf("\n");
}
int q_sort(int *s, int low, int high) {
if (low < high) {
int temp = sort(s, low, high);
sort(s, low, temp - 1);
sort(s, temp + 1, high);
}
return 0;
}
int sort(int *s, int low, int high) {
int pivot = s[low];
while (low < high) {
while (low < high && s[high] >= pivot)
--high;
s[low] = s[high];
while (low < high && s[low] <= pivot)
++low;
s[high] = s[low];
}
s[low] = pivot;
return low;
}
int main(int argc, const char *argv[]) {
//int s[10]={10,2,3,4,5,6,7,9,12,8};
int s[10] = {4, 9, 8, 7, 2, 3, 5, 6, 50, 45};
q_sort(s, 0, 9);
p_sort(s);
return 0;
}
```
这样修改后的代码应该可以正确运行了。
相关推荐
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)