以 公有成员为准 对class进行排序
2013-04-09 22:25
351 查看
int 必须为 public (目前我只是自己研究透这个) 排序准则可以重载 默认升序 重载例如: bool compare(const student &x, const student &y) //降序排列 compar 可以换任意名字 { return x.score > y.score; } 整体代码为: #include<iostream> #include<vector> #include<algorithm> #include<string> using namespace std; class student { public: string name; int score; student(string str ,int score1) { name=str; score=score1; } string getname() { return name; } void disp() { cout<<"name: "<<name<<" score:"<<score<<endl; } }; bool compare(const student &x, const student &y) //降序排列 { return x.score > y.score; } int main() { student st[]={student("王华",78),student("shilei",100),student("范兄",99),student("小屁孩",56)}; vector <student> vec; for(int i=0;i<4;++i) vec.push_back(st[i]); sort(vec.begin(),vec.end(),compare); //compare 为排序基准 名字随意 cout<<"排序输出结果为:"<<endl; for(vector<student>::iterator it=vec.begin();it!=vec.end();it++) it->disp(); }
相关文章推荐
- Intellij IDEA怎么像Eclipse一样对Class成员进行排序
- HashMap中的对象根据成员进行自定义排序
- ios字典存到数组当中进行年龄降序排序,然后删除指定的成员信息
- mapreduce 利用InverseMapper.class对key,value进行 交换实现词频排序
- 使用ASM对JAVA class file进行修改的技术 -- 添加类成员
- 对List对象按照某个成员变量进行排序
- mapreduce 利用InverseMapper.class对key,value进行 交换实现词频排序 .
- C语言单向动态链表程序,实现链表的建立,合并,重新排序,链表元素的插入与删除,以及根据元素成员的值进行元素删除。
- 对类依据成员进行排序
- set不能通过指针元素指向的成员进行排序
- 在类外成员函数中进行输入排序和输出
- mapreduce 利用InverseMapper.class对key,value进行 交换实现词频排序
- list结构体根据某个成员进行排序
- HashMap中的对象根据成员进行自定义排序
- 使用hadoop进行排序时报错 Error: java.lang.ClassCastException
- 4.5 根据辅助属性对属性成员进行排序
- 对vector成员进行排序
- 结构体数组中的某个成员进行排序
- 如何使用arraylist对存放class中某个元素进行排序
- 6.对数组进行排序、求最大值和求元素和的函数采用静态成员函数的方式封装成数组算法类模板ArrayAlg,并采用相关数据进行测试。