mozibumozi 2022-01-02 18:16 采纳率: 37.5%
浏览 33
已结题

请问怎么下面函数的基础上修改QKPass函数,实现双关键字排序

问题遇到的现象和发生背景
#include<stdio.h>
#define max 100 
typedef  struct{
    int key;     
}RecoedType;
typedef  struct {
    RecoedType r[max+1];
    int length;
}RecoedList;

int QKPass(RecoedType r[],int low,int high){
    RecoedType x=r[low];
    while(low<high){
        while(low<high&&r[high].key>x.key)
        high--;
        if(low<high)
        {
            r[low]=r[high];
        
            low++;
        }
        while(low<high&&r[low].key<x.key)
        low++;
        if(low<high){
        r[high]=r[low];
    
        high--;
        }
        }
        r[low]=x;
        return low;
    }
void QKSort( RecoedType r[],int low,int high){
    RecoedType b[max+1];
    int pos;
    if(low<high){
        pos=QKPass(r,low,high);
        QKSort(r,low,pos-1);
        QKSort(r,pos+1,high);
    }
}
int main(){

    RecoedList L;
    printf("请输入数组长度:"); 
    scanf("%d",&L.length);
    int low,high;
    printf("排序前:\n");
    for(int i=1;i<=L.length ;i++){
        scanf("%d,%d",&L.r[i].key);
    }
     QKSort(L.r,1,L.length );
     printf("排序后:\n");
   for( int i=1;i<=L.length;i++){
       printf("  %d,%d",&L.r[i]);
   }    
   
return 0;
}

问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 1月10日
    • 创建了问题 1月2日