diff --git a/greedy/Job_sequencing.cpp b/greedy/Job_sequencing.cpp new file mode 100644 index 0000000..d4c9a4e --- /dev/null +++ b/greedy/Job_sequencing.cpp @@ -0,0 +1,65 @@ +// Program to find the maximum profit job sequence from a given array +// of jobs with deadlines and profits +#include +#include +using namespace std; + +// A structure to represent a job +struct Job +{ +char id; // Job Id +int dead; // Deadline of job +int profit; // Profit if job is over before or on deadline +}; + +// This function is used for sorting all jobs according to profit +bool comparison(Job a, Job b) +{ + return (a.profit > b.profit); +} + +// Returns minimum number of platforms required +void printJobScheduling(Job arr[], int n) +{ + // Sort all jobs in decreasing order of profit + sort(arr, arr+n, comparison); + + int result[n]; // (Sequence of jobs) + bool slot[n]; // free time slots + + // Initialize all slots + for (int i=0; i=0; j--) + { + if (slot[j]==false) + { + result[j] = i; // Add this job to result + slot[j] = true; // Make this slot occupied + break; + } + } + } + + // Print the result + for (int i=0; i