64,654
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
class Job
{
public:
int ID;
int time;
void set(int ID,int time)
{
this->ID=ID;
this->time=time;
}
void print()
{
cout<<"("<<ID<<","<<time<<")"<<endl;
}
};
bool comp_job( Job j1, Job j2)
{
return j1.time>j2.time;
}
void main()
{
vector<Job> x(3);
x[0].set(0,1);
x[1].set(1,5);
x[2].set(2,3);
//Job m;
list <Job> y;
list<Job>::iterator i;
y.push_back(x[0]);
y.push_back(x[1]);
y.push_back(x[2]);
sort(y.begin(),y.end(),comp_job);
for (i=y.begin();i!=y.end();i++)
{
i->print();
}
}
#include <iostream>
#include <vector>
#include <list>
#include <algorithm>
using namespace std;
class Job
{
public:
int ID;
int time;
void set(int ID,int time)
{
this->ID=ID;
this->time=time;
}
void print()
{
cout<<"("<<ID<<","<<time<<")"<<endl;
}
friend bool operator < (Job j1, Job j2)
{
return j1.time < j2.time;
}
};
void main()
{
vector<Job> x(3);
x[0].set(0,1);
x[1].set(1,5);
x[2].set(2,3);
//Job m;
list <Job> y;
list<Job>::iterator i;
y.push_back(x[0]);
y.push_back(x[1]);
y.push_back(x[2]);
y.sort();
for (i=y.begin();i!=y.end();i++)
{
i->print();
}
system("pause");
}