问题遇到的现象和发生背景
查找中位数时出错
问题相关代码,请勿粘贴截图
//定义学生结构
struct Student
{
int sno,sco;
char gender,major,cno;
};
//从中间逼近
int Partition(struct Student *S,int low,int high)
{
S[0]= S[low];
int pivotkey = S[low].sco;
while(low < high){
while(low < high && S[high].sco >= pivotkey) --high;
S[low] = S[high];
while (low < high && S[high].sco <= pivotkey) ++low;
S[high] = S[low];
}
S[low] = S[0];
// printf("low = %d\n",low);
return low;
}
void FindMid(struct student *Sstudents1,int low,int high)
{
int mid=(low+high)/2;
// printf("n=%d\t",n);
// printf("high=%d\t",high);
while(1){
int p=Partition(Sstudents1,low,high);
if(p==mid)
break;
else if(p>mid)
high=p-1;
else low=p+1;
}
printf("%d",Sstudents1[mid].sco);
}
报错内容
Subscript of pointer to incomplete type 'struct student'
我想要达到的结果
主要问题就是 printf("%d",Sstudents1[mid].sco);报错Sstudents1[mid].sco好像不能这么写,求正确写法或替代方法
感谢