文章

1

粉丝

37

获赞

0

访问

391

头像
各位大佬帮我看看为什么我的通过率只有66%
我要提问
发布于2024年1月5日 22:38
阅读数 391

1010排序

Time Limit: 1000 ms
Memory Limit: 256 mb

输入n个数进行排序,要求先按奇偶后按从小到大的顺序排序

代码如下:

#include <stdio.h>

int Partition1(int a[], int low, int high){
    int pivot=a[low];
    while(low<high){
        while(low<high&&a[high]%2==0)
            high--;
        a[low]=a[high];
        while(low<high&&a[low]%2!=0)
            low++;
        a[high]=a[low];
    }
    a[low]=pivot;
    return low;
}

int Partition2(int a[], int low, int high){
    int pivot=a[low];
    while(low<high){
        while(low<high&&a[high]>=pivot)
          ...

登录查看完整内容


登录后发布评论

1 条评论
snake
2024年1月6日 19:40

主函数直接以mid划分感觉有点问题,奇偶应该有区别

赞(1)