@@ -87,9 +87,6 @@ struct Job {
87
87
int profit; // Profit earned if job is completed before deadline
88
88
}; // namespace greedy_algorithmsstruct Job
89
89
90
- // Custom sorting helper struct which is used for sorting
91
- // all jobs according to profit
92
-
93
90
/* *
94
91
* @brief Utility function that finds Custom sorting helper
95
92
* struct which is used for sorting all jobs according to profit
@@ -98,11 +95,7 @@ struct Job {
98
95
* @param b second job struct
99
96
* @returns true if the proft of a less than profit of b, else false.
100
97
*/
101
- struct jobProfit {
102
- bool operator ()(Job const & a, Job const & b) {
103
- return (a.profit < b.profit );
104
- }
105
- };
98
+ bool jobComparator (Job const &a, Job const &b) { return (a.profit < b.profit ); }
106
99
107
100
/* *
108
101
* @brief function that get the maximum profit from jobs
@@ -118,7 +111,8 @@ std::vector<char> getJobScheduling(Job arr[], int n) {
118
111
std::sort (arr, arr + n, [](Job a, Job b) { return a.dead < b.dead ; });
119
112
120
113
// set a custom priority queue
121
- std::priority_queue<Job, std::vector<Job>, jobProfit> pq;
114
+ std::priority_queue<Job, std::vector<Job>, decltype (&jobComparator)> pq (
115
+ jobComparator);
122
116
123
117
for (int i = n - 1 ; i >= 0 ; i--) {
124
118
int slot_available;
@@ -194,4 +188,4 @@ void tests() {
194
188
int main () {
195
189
tests ();
196
190
return 0 ;
197
- }
191
+ }
0 commit comments