From ba9871fce074b40b219cd6875fa4bef3708a615c Mon Sep 17 00:00:00 2001 From: Adit Mehta <35133994+aditmehta9@users.noreply.github.com> Date: Sun, 7 Oct 2018 01:16:37 +0530 Subject: [PATCH] Job sequencing code in C++ --- job_sequencing.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 job_sequencing.cpp diff --git a/job_sequencing.cpp b/job_sequencing.cpp new file mode 100644 index 00000000..ead9e536 --- /dev/null +++ b/job_sequencing.cpp @@ -0,0 +1,52 @@ +#include +#include +using namespace std; + +struct Job +{ + char id; + int dead; + int profit; +}; + +bool comparison(Job a, Job b) +{ + return (a.profit > b.profit); +} +void printJobScheduling(Job arr[], int n) +{ + sort(arr, arr+n, comparison); + + int result[n]; + bool slot[n]; + for (int i=0; i=0; j--) + { + + if (slot[j]==false) + { + result[j] = i; + slot[j] = true; + break; + } + } + } + + for (int i=0; i