如何将形参指针所指结构体数组中的三个元素按num成员进行升序排列

#include <stdio.h>
typedef struct
{ int num;
char name[10];
}PERSON;
/**********found**********/
void fun(PERSON ___1___)
{
/**********found**********/
___2___ temp;
if(std[0].num>std[1].num)
{ temp=std[0]; std[0]=std[1]; std[1]=temp; }
if(std[0].num>std[2].num)
{ temp=std[0]; std[0]=std[2]; std[2]=temp; }
if(std[1].num>std[2].num)
{ temp=std[1]; std[1]=std[2]; std[2]=temp; }
}
main()
{ PERSON std[ ]={ 5,"Zhanghu",2,"WangLi",6,"LinMin" };
int i;
/**********found**********/
fun(___3___);
printf("\nThe result is :\n");
for(i=0; i<3; i++)
printf("%d,%s\n",std[i].num,std[i].name);
}
请大侠帮忙做下,谢谢!!·

千万里不及你
浏览 94回答 2
2回答

汪汪一只猫

第一空,PERSON std[] 或者 PERSON *std,将学生数组作为参数,从后面的“std[0]”下标能够推断出参数是数组类型(指针类型);第二空,PERSON temp,这一点从“temp=std[0];”可以推断出temp的类型;第三空,fun(std),将std数组作为形参传入到函数。

幕布斯7119047

1: *std2: PERSON3: &std
打开App,查看更多内容
随时随地看视频慕课网APP