代码拉取完成,页面将自动刷新
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
struct Employee {
public:
std::string name, id;
bool isFulltime;
};
bool comparator( Employee * op1, Employee * op2 ) {
if( op1->id.size() != op2->id.size() ) {
if( op1->id.size() < op2->id.size() )
return true;
return false;
}
return op1->id < op2->id;
}
// bool comparator( Employee * op1, Employee * op2 ) {
// if( op1->isFulltime != op2->isFulltime )
// return op1->isFulltime;
// if( op1->id.size() != op2->id.size() ) {
// if( op1->id.size() < op2->id.si ze() )
// return true;
// return false;
// }
// return op1->id < op2->id;
// }
int main() {
Employee e1, e2, e3, e4;
e1.name = "Cindy"; e1.id = "20180915"; e1.isFulltime = false;
e2.name = "Simon"; e2.id = "20180309"; e2.isFulltime = false;
e3.name = "Jennifer"; e3.id = "370"; e3.isFulltime = true;
e4.name = "Paul"; e4.id = "20181002"; e4.isFulltime = true;
std::map<std::string,Employee*> staff;
staff["Cindy"] = &e1;
staff["Simon"] = &e2;
staff["Jennifer"] = &e3;
staff["Paul"] = &e4;
std::vector<Employee*> reorderedStaff( staff.size() );
int i = 0;
for( std::map<std::string,Employee*>::iterator it = staff.begin(); it != staff.end(); it++ )
reorderedStaff[i++] = it->second;
std::sort( reorderedStaff.begin(), reorderedStaff.end(), comparator );
for( std::vector<Employee*>::iterator it = reorderedStaff.begin(); it != reorderedStaff.end(); it++ )
std::cout << (*it)->id << ": " << (*it)->name << std::endl;
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。