diff --git a/Interval Scheduling.C b/Interval Scheduling.C new file mode 100644 index 0000000..d6bb5c8 --- /dev/null +++ b/Interval Scheduling.C @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include + +const int jobCnt = 10; + +// Job start times +const int startTimes[] = { 2, 3, 1, 4, 3, 2, 6, 7, 8, 9}; + +// Job end times +const int endTimes[] = { 4, 4, 3, 5, 5, 5, 8, 9, 9, 10}; + +using namespace std; + +int main() +{ + vector> jobs; + + for(int i=0; i p1, pair p2) + { return p1.second < p2.second; }); + + // step 2: empty set A + vector A; + + // step 3: + for(int i=0; i= jobs[jobIndex].first && + job.first <= jobs[jobIndex].second) + { + isCompatible = false; + break; + } + } + + if(isCompatible) + A.push_back(i); + } + + //step 4: print A + cout << "Compatible: "; + + for(auto i : A) + cout << "(" << jobs[i].first << "," << jobs[i].second << ") "; + cout << endl; + + return 0; +} \ No newline at end of file