TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
Loading...
Searching...
No Matches
Compare< S, T, E > Class Template Reference

Comparator class for priority queue. More...

Public Member Functions

bool operator() (tuple< S, T, E, double, double, double > &t1, tuple< S, T, E, double, double, double > &t2)
 A comparator function that checks whether to swap the two tuples or not. to https://www.geeksforgeeks.org/comparator-class-in-c-with-examples/ for detailed description of comparator.
 
bool operator() (tuple< S, T, E, double, double, double > &t1, tuple< S, T, E, double, double, double > &t2)
 A comparator function that checks whether to swap the two tuples or not. detailed description of comparator
 

Detailed Description

template<typename S, typename T, typename E>
class Compare< S, T, E >

Comparator class for priority queue.

Template Parameters
SData type of Process ID
TData type of Arrival time
EData type of Burst time

Definition at line 63 of file fcfs_scheduling.cpp.

Member Function Documentation

◆ operator()() [1/2]

template<typename S , typename T , typename E >
bool Compare< S, T, E >::operator() ( tuple< S, T, E, double, double, double > & t1,
tuple< S, T, E, double, double, double > & t2 )
inline

A comparator function that checks whether to swap the two tuples or not. to https://www.geeksforgeeks.org/comparator-class-in-c-with-examples/ for detailed description of comparator.

Parameters
t1First tuple
t2Second tuple
Returns
true if the tuples SHOULD be swapped
false if the tuples SHOULDN'T be swapped

Definition at line 76 of file fcfs_scheduling.cpp.

77 {
78 // Compare arrival times
79 if (get<1>(t2) < get<1>(t1)) {
80 return true;
81 }
82 // If arrival times are same, then compare Process IDs
83 else if (get<1>(t2) == get<1>(t1)) {
84 return get<0>(t2) < get<0>(t1);
85 }
86 return false;
87 }

◆ operator()() [2/2]

template<typename S , typename T , typename E >
bool Compare< S, T, E >::operator() ( tuple< S, T, E, double, double, double > & t1,
tuple< S, T, E, double, double, double > & t2 )
inline

A comparator function that checks whether to swap the two tuples or not. detailed description of comparator

Parameters
t1First tuple
t2Second tuple
Returns
true if the tuples SHOULD be swapped
false if the tuples SHOULDN'T be swapped

Definition at line 74 of file non_preemptive_sjf_scheduling.cpp.

75 {
76 // Compare burst times for SJF
77 if (get<2>(t2) < get<2>(t1)) {
78 return true;
79 }
80 // If burst times are the same, compare arrival times
81 else if (get<2>(t2) == get<2>(t1)) {
82 return get<1>(t2) < get<1>(t1);
83 }
84 return false;
85 }

The documentation for this class was generated from the following files: