#include "stdafx.h"
#include "malloc.h"
#include "windows.h"
struct student
{
int x;
};
//冒泡排序:对结构体或者类进行排序,如果不能实现,找出问题所在.
template<class A, class Stu>
void Sort(A a, Stu s, int len) {
for (int i = 0; i < len - 1; i++) {
if (a[i] > a[i + 1]) {
s = a[i];
a[i] = a[i + 1];
a[i + 1] = s;
}
}
}
int main()
{
student stu1, stu2, stu3, stu4, s;
s.x = 0;
stu1.x = 10;
stu2.x = 5;
stu3.x = 9;
stu4.x = 80;
student arr[] = { stu1, stu2, stu3, stu4 };
Sort(arr, s, 4);
for (int i = 0; i < 5; i++) {
printf("%d\n", arr[i].x);
}
getchar();
return 0;
}
冒泡排序:对结构体或者类进行排序,如果不能实现,找出问题所在
最新推荐文章于 2021-05-20 09:54:00 发布