C语言结构体数组成员做参数的函数调用问题,如何做到递归调用? 30
#include<stdio.h>structthree{intw,v;//重量,价格doublep;//性价比}A[1000];intPartition(intlow,...
#include<stdio.h>struct three{ int w,v;//重量,价格 double p;//性价比 }A[1000];int Partition(int low,int high,three A[],int three::*whichmen){ int i=low,j=high,t=0; while(i<j&&A[j].*whichmen>A[low].*whichmen) j--; while(i<j&&A[i].*whichmen<A[low].*whichmen) i++; if(i<j){ t=A[j].*whichmen;A[j].*whichmen=A[i].*whichmen;A[i].*whichmen=t; i++;j--; } if(A[i].*whichmen>A[low].*whichmen){ t=A[low].*whichmen;A[low].*whichmen=A[i-1].*whichmen;A[i-1].*whichmen=t; return i-1; } else{ t=A[low].*whichmen;A[low].*whichmen=A[i].*whichmen;A[i].*whichmen=t; return i; }}void QuickSort(int low,int high,int A[],int three::*whichmen){ int mid; while(low<high){ mid=Partition(low,high,A,&three::whichmen); QuickSort(low,mid-1,A,&three::whichmen); QuickSort(mid+1,high,A,&three::whichmen); }}int main(){ int i; for(i=0;i<5;i++){ scanf("%d",&A[i].w); } QuickSort(0,4,A,&three::w); for(i=0;i<5;i++){ printf("%d",A[i].w); } return 0;}代码如图所示,黑色图片那块地方为递归调用,但是有错误,本人能力有限无法解决这个错误,恳请大佬们帮助,谢谢。
展开
展开全部
我现写的一个,简洁明了,应该是符合你的口味的,测试完全通过 #include #define N 100 typedef struct student { int id; //学号 char name[20]; //姓名 int gender; //性别(0代表男生,1代表女生) float score; //成绩 }stu; stu s[N]; int main() { int i; for(i=0;iid,(p+i)->name,(p+i)->gender,(p+i)->score); } return 0; }
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询