bubble sort 问题
#include <stdio.h>#define MAXDATA 1000
struct elem {
char name[16];
int x,y;
}elem[MAXDATA+1];
int max;
int main(){
/*input*/
printf("*********************.\n");
printf("*sort start ***\n");
printf("*********************.\n");
set_data();
sort_data();
dump_data();
printf("*********************.\n");
printf("*sort finish ***\n");
printf("*********************.\n");
return 0;
}
int set_data(){
int i;
strcpy(elem[0].name,"A");elem[0].x = 1; elem[0].y = 2;
strcpy(elem[1].name,"B");elem[1].x = 3; elem[1].y = 3;
strcpy(elem[2].name,"C");elem[2].x = 2; elem[2].y = 4;
strcpy(elem[3].name,"D");elem[3].x = 4; elem[3].y = 6;
strcpy(elem[4].name,"E");elem[4].x = 5; elem[4].y = 8;
strcpy(elem[5].name,"F");elem[5].x = 2; elem[5].y = 1;
strcpy(elem[6].name,"G");elem[6].x = 4; elem[6].y = 4;
strcpy(elem[7].name,"H");elem[7].x = 8; elem[7].y = 2;
strcpy(elem[8].name,"I");elem[8].x = 3; elem[8].y = 1;
strcpy(elem[9].name,"J");elem[9].x = 2; elem[9].y = 4;
strcpy(elem[10].name,"K");elem[10].x = 1; elem[10].y = 1;
strcpy(elem[11].name,"L");elem[11].x = 8; elem[11].y = 2;
strcpy(elem[12].name,"M");elem[12].x = 3; elem[12].y = 1;
strcpy(elem[13].name,"N");elem[13].x = 2; elem[13].y = 4;
strcpy(elem[14].name,"O");elem[14].x = 1; elem[14].y = 9;
max = 15;
return 0;
}
int sort_data(){
int cf,i;
}
int dump_data(){
int i;
printf("*********** dump data: %d ****************.\n", max);
for(i=0; i<max;i++)
printf("%s %d %d\n", elem[i].name, elem[i].x, elem[i].y);
printf("********* dump data end *****************.\n", max);
return 0;
}
目的 完成
int sort_data(){
}
利用bubble sort方法 把elem[i].x坐标由小到大的顺序把数组重新排列
再把新数组输出