-
Notifications
You must be signed in to change notification settings - Fork 0
/
interval.cpp
49 lines (40 loc) · 985 Bytes
/
interval.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
class Interval {
public:
Interval(int start, int end, int weight) : start(start), end(end), weight(weight) {}
~Interval() {}
int start;
int end;
int weight;
};
/** Return the max weight of non-overlapping intervals. */
struct Comparator {
bool operator()(Interval & first, Interval & second) {
return first.end > second.end;
}
};
void TestSort(vector<Interval> vec) {
sort(vec.begin(), vec.end(), Comparator());
for (int i = 0; i < vec.size(); i++) {
std::cout << vec[i].start << " " << vec[i].end << " " << vec[i].weight << std::endl;
}
}
int MaxWeight(vector<Interval> &vec) {
}
int main() {
vector<Interval> intervalVec;
Interval itl1(0, 3, 1);
Interval itl2(2, 7, 2);
Interval itl3(4, 5, 2);
intervalVec.push_back(itl1);
intervalVec.push_back(itl2);
intervalVec.push_back(itl3);
TestSort(intervalVec);
return 0;
}