user-0 提问: 求各位大佬帮帮忙

回复:
user: user-0
content: 引用 11 楼 chxchxkkk的回复:把你的代码修改了一下，参考  #include <stdio.h> #include <stdlib.h> #include <math.h>  //定义结构体 typedef struct staff {     int id ;     char gender[8];     char name[20]; }STA;  //定义一个数组 STA stas[]={     {23,"男","王火"},     {12,"男","宜丰"},     {45,"女","张小花"},     {18,"男","李超"},     {18,"女","万思思"},     {77,"女","吴方"},     {4,"男","刘一明"},     {96,"男","邓伟"}, };  int main() {     STA temp;     int i,j;     for(i=0; i<8; i++)     {         for (j=0; j<8-1-i; j++)         {            if(stas[j].id>stas[j+1].id)            {                temp=stas[j];                stas[j]=stas[j+1];                stas[j+1]=temp;            }         }      }      printf("\n学号\t性别\t姓名\n");     for (i=0; i<8; i++)     {         printf("%d\t%s\t%s\n",stas[i].id, stas[i].gender, stas[i].name);     }     return 0; }  感谢大佬

user: user-1
content: 不影响啊，符合条件的直接交换结构体了

user: user-1
content: 把你的代码修改了一下，参考  #include <stdio.h> #include <stdlib.h> #include <math.h>  //定义结构体 typedef struct staff {     int id ;     char gender[8];     char name[20]; }STA;  //定义一个数组 STA stas[]={     {23,"男","王火"},     {12,"男","宜丰"},     {45,"女","张小花"},     {18,"男","李超"},     {18,"女","万思思"},     {77,"女","吴方"},     {4,"男","刘一明"},     {96,"男","邓伟"}, };  int main() {     STA temp;     int i,j;     for(i=0; i<8; i++)     {         for (j=0; j<8-1-i; j++)         {            if(stas[j].id>stas[j+1].id)            {                temp=stas[j];                stas[j]=stas[j+1];                stas[j+1]=temp;            }         }      }      printf("\n学号\t性别\t姓名\n");     for (i=0; i<8; i++)     {         printf("%d\t%s\t%s\n",stas[i].id, stas[i].gender, stas[i].name);     }     return 0; }

user: user-0
content: 引用 8 楼 chxchxkkk的回复:不影响啊，符合条件的直接交换结构体了 #include <stdio.h> #include <stdlib.h> #include <math.h>  typedef struct staff{//定义结构体 	int id ; 	char gender[8]; 	char name[20]; }STA; STA stas[]={//定义一个数组 	{23,"男","王火"}, 	{12,"男","宜丰"}, 	{45,"女","张小花"}, 	{18,"男","李超"}, 	{18,"女","万思思"}, 	{77,"女","吴方"}, 	{4,"男","刘一明"}, 	{96,"男","邓伟"} };  int main(){ STA temp; int i; for(i=0;i<=7;i++) { if(stas[i].id>stas[i+1].id) { 	temp=stas[i]; 	stas[i]=stas[i+1]; 	stas[i+1]=temp; }  printf("%c\n",stas[i] ); }return 0; } 大佬我这个代码错了他输出只输出了数字

user: user-0
content: 引用 8 楼 chxchxkkk的回复:不影响啊，符合条件的直接交换结构体了 okk谢啦大佬

user: user-0
content: 引用 6 楼 chxchxkkk的回复:[quote=引用 5 楼 I  don＇t  know 的回复:] [quote=引用 2 楼 qybao的回复:]用个结构体数组就可以 typedef struct staff { //定义结构体     int id;     char gender[8];     char name[20]; } STA;  STA stas[]={ //定义一个数组     {23, “男”, “王火”},     {12, “男”, “宜丰”},     ...     {96, “男”, “邓伟”} }; 大佬如果需要用里面的数字比较大小排序该怎么做呢？[/quote]   定义个临时结构体，然后用学号排序 STA temp; 然后循环排序 if (stas[i].id < stas[i+1]) {     temp =  stas[i];     stas[i] = stas[i+1];     stas[i+1] = temp; }[/quote] 大佬我有个问题，他们里面有字符串，不会影响比较嘛，感谢

user: user-1
content: 引用 5 楼 I  don＇t  know 的回复:[quote=引用 2 楼 qybao的回复:]用个结构体数组就可以 typedef struct staff { //定义结构体     int id;     char gender[8];     char name[20]; } STA;  STA stas[]={ //定义一个数组     {23, “男”, “王火”},     {12, “男”, “宜丰”},     ...     {96, “男”, “邓伟”} }; 大佬如果需要用里面的数字比较大小排序该怎么做呢？[/quote]   定义个临时结构体，然后用学号排序 STA temp; 然后循环排序 if (stas[i].id < stas[i+1]) {     temp =  stas[i];     stas[i] = stas[i+1];     stas[i+1] = temp; }

user: user-0
content: 引用 2 楼 qybao的回复:用个结构体数组就可以 typedef struct staff { //定义结构体     int id;     char gender[8];     char name[20]; } STA;  STA stas[]={ //定义一个数组     {23, “男”, “王火”},     {12, “男”, “宜丰”},     ...     {96, “男”, “邓伟”} }; 大佬如果需要用里面的数字比较大小排序该怎么做呢？

user: user-0
content: 引用 2 楼 qybao的回复:用个结构体数组就可以 typedef struct staff { //定义结构体     int id;     char gender[8];     char name[20]; } STA;  STA stas[]={ //定义一个数组     {23, “男”, “王火”},     {12, “男”, “宜丰”},     ...     {96, “男”, “邓伟”} }; 十分感谢大佬

user: user-0
content: 引用 1 楼 user-3的回复:用你属性的，数组就好，没有说一定要链表 感谢大佬。。

user: user-2
content: 用个结构体数组就可以 typedef struct staff { //定义结构体     int id;     char gender[8];     char name[20]; } STA;  STA stas[]={ //定义一个数组     {23, “男”, “王火”},     {12, “男”, “宜丰”},     ...     {96, “男”, “邓伟”} };

user: user-3
content: 用你属性的，数组就好，没有说一定要链表