1. 程式人生 > 其它 >二維陣列按某列排序交換元素

二維陣列按某列排序交換元素

技術標籤:排序演算法堆排序快速排序插入排序演算法導論

二維陣列按某列排序需要交換各個列的元素;此時利用結構體陣列比較方便,結構體陣列可以直接交換,裡面的各個成員就i能交換了。

#include "stdio.h"
#include "stdlib.h"
void main() {
 struct student
 {
  int age;
  float score;
 };
 struct student a, b;
 a.age = 10; a.score = 100;
 b.age = 11; b.score = 99;
 struct student c;
 c = a;
 a = b;
 b = c;
 printf("a:%d %f\n", a.age, a.score);
 printf("b:%d %f\n", b.age, b.score);
 system("pause");
}