对给定关键字序号j(1<j<n),要求在无序记录A[1…n]中找到关键字从小到大排在第j位上的记录,写一个算法利用快速排序的划分思想实现上述查找(要求用最少的时间和最少的空间)
/*利用快速排序的划分思想在无序记录中查找给定关键字序号的记录*/
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#define MAXSIZE 20
typedef int KeyType;
typedef int InfoType;
typedef struct
{
KeyType key;
InfoType otherinfo;
}RedType;
typedef struct
{
RedType r[MAXSIZE+1];
int length;
}SqList;
int Partition(SqList *L,int low,int high);
KeyType QSort(SqList *L,int low,int high,int i);
void QuickSort(SqList *L,int i);
int main()
{
int c;
SqList *L;
L=(SqList *)malloc(sizeof(SqList));
int i;
printf("需排序的项数为:");
scanf("%d",&L->length);
for(i=0;i<L->length;i++)
{
printf("please input the number:");
scanf("%d",&L->r[i+1].key);
}
printf("\n需要查找第几位?:");
scanf("%d",&c)