表格排序该怎么写呢
名称 数据甲 20
乙 10
丙 15
丁 30
根据数据的大小排序,这该怎么写呢

程序代码:#include <iostream>
#include <string>
using namespace std;
class A {
public:
A(const int n, const char *m)
: num(n), name(m) {}
A(const A &b)
: num(b.num), name(b.name) {}
~A() {}
bool operator<(const A &b) const // 重载这个
{ return num < b.num ? true : (num == b.num && name < b.name); }
void swap(A &b) // 和这个函数,程序就好写了。
{
int t = num; num = b.num; b.num = t;
name.swap(b.name);
}
friend ostream &operator<< (ostream &, const A &);
private:
int num;
string name;
};
ostream &operator<< (ostream &out, const A &a)
{
out << a.num << ": " << a.name;
return out;
}
void sort(A x[], int n) // 排列基本还是用你写的。
{
int i, j;
for (i = 0; i < n-1; i++)
for (j = 0; j < n-i-1; j++)
{
if (x[j+1] < x[j])
x[j].swap(x[j+1]);
}
}
int main(int argc, char *argv[])
{
A test[5] = {
A(1, "b"),
A(1, "a"),
A(2, "b"),
A(5, "a"),
A(0, "z"),
};
sort(test, 5);
int i;
for (i = 0; i < 5; i++) {
cout << test[i] << endl;
}
return 0;
}