#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct{ int NO; int Age; char Name[50]; }Student; typedef struct{ int StudentCount; Student *data; }Sqlist; void SelectSort(Sqlist &L) { int i,j,min; Student p; for(i=0;i<L.StudentCount-1;i++) //i到n-1 { min=i; for(j=i+1;j<L.StudentCount;j++) //j到n if(L.data[j].NO<L.data[min].NO) min=j; if(min!=i) { p=L.data[min]; L.data[min]=L.data[i]; L.data[i]=p; } } } int main() { Sqlist L; L.StudentCount=4; L.data = (Student *)malloc(L.StudentCount * sizeof(Student)); L.data[0].Age=20; strcpy(L.data[0].Name,"zhangsan"); L.data[0].NO=1115; L.data[1].Age=20; strcpy(L.data[1].Name,"lisi"); L.data[1].NO=1112; L.data[2].Age=20; strcpy(L.data[2].Name,"wanger"); L.data[2].NO=1113; L.data[3].Age=20; strcpy(L.data[3].Name,"mazi"); L.data[3].NO=1114; SelectSort(L); for (int i = 0; i < L.StudentCount; i++) { printf("NO: %d, Age: %d, Name: %s\n", L.data[i].NO, L.data[i].Age, L.data[i].Name); } return 0; }
标签:typedef,include,struct,int,选择,Student,Sqlist,排序 From: https://www.cnblogs.com/simpleset/p/17871667.html