C++ class中写sort二级排序

  做tc时被这个问题纠结住了,后来问了大牛,可以这样写。

 1 class EvenRoute {
2 public:
3 struct node {
4 int x;
5 int y;
6 node(int a = 0, int b = 0) : x(a), y(b) {}
7 };
8
9 static bool cmp(const node& c, const node& d) {   //加static
10 if(c.x == d.x) return c.y < d.y;
11 return c.x < d.x;
12 }
13
14 string isItPossible(vector <int> x, vector <int> y, int w) {
15 struct node a[1000];
16 int n = 1000;
17 //....
18 sort(a, a + n, cmp);
19 return "CAN";
20 }
21 };



posted @ 2012-03-21 09:48  AC_Von  阅读(1439)  评论(0编辑  收藏  举报