Skip to content

Commit 6ebca75

Browse files
Update non_preemptive_sjf_scheduling.cpp
1 parent 16d952f commit 6ebca75

File tree

1 file changed

+23
-26
lines changed

1 file changed

+23
-26
lines changed

cpu_scheduling_algorithms/non_preemptive_sjf_scheduling.cpp

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -135,24 +135,21 @@ class SJF {
135135
}
136136

137137
/**
138-
* @brief Algorithm for scheduling CPU processes according to the Shortest Job
139-
First (SJF) scheduling algorithm.
140-
*
141-
* @details Non pre-emptive SJF is an algorithm that schedules processes based
142-
on the length
143-
* of their burst times. The process with the smallest burst time is executed
144-
first.
145-
* In a non-preemptive scheduling algorithm, once a process starts executing,
146-
* it runs to completion without being interrupted.
147-
*
148-
* I used a min priority queue because it allows you to efficiently pick the
149-
process
150-
* with the smallest burst time in constant time, by maintaining a priority
151-
order where
152-
* the shortest burst process is always at the front.
153-
*
154-
* @returns void
155-
*/
138+
* @brief Algorithm for scheduling CPU processes according to
139+
* the Shortest Job First (SJF) scheduling algorithm.
140+
*
141+
* @details Non pre-emptive SJF is an algorithm that schedules processes
142+
* based on the length of their burst times. The process with the smallest
143+
* burst time is executed first.In a non-preemptive scheduling algorithm,
144+
* once a process starts executing,it runs to completion without being
145+
* interrupted.
146+
*
147+
* I used a min priority queue because it allows you to efficiently pick the
148+
* process with the smallest burst time in constant time, by maintaining a
149+
* priority order where the shortest burst process is always at the front.
150+
*
151+
* @returns void
152+
*/
156153

157154
vector<tuple<S, T, E, double, double, double>> scheduleForSJF() {
158155
// Variable to keep track of time elapsed so far
@@ -192,8 +189,8 @@ class SJF {
192189
return result;
193190
}
194191
/**
195-
* @brief Utility function for printing the status of each process after
196-
* execution
192+
* @brief Utility function for printing the status of
193+
* each process after execution
197194
* @returns void
198195
*/
199196

@@ -217,8 +214,8 @@ class SJF {
217214
};
218215

219216
/**
220-
* @brief Computes the final status of processes after applying non-preemptive
221-
* SJF scheduling
217+
* @brief Computes the final status of processes after
218+
* applying non-preemptive SJF scheduling
222219
* @tparam S Data type of Process ID
223220
* @tparam T Data type of Arrival time
224221
* @tparam E Data type of Burst time
@@ -290,8 +287,8 @@ static void test() {
290287
}
291288

292289
// Print processes before scheduling
293-
// cout << "Processes before SJF scheduling:" << endl;
294-
// readyQueue.printResult(input);
290+
cout << "Processes before SJF scheduling:" << endl;
291+
readyQueue.printResult(input);
295292

296293
// Add processes to the queue
297294
for (uint32_t i{}; i < n; i++) {
@@ -303,8 +300,8 @@ static void test() {
303300
auto finalResult = readyQueue.scheduleForSJF();
304301

305302
// Print processes after scheduling
306-
// cout << "\nProcesses after SJF scheduling:" << endl;
307-
// readyQueue.printResult(finalResult);
303+
cout << "\nProcesses after SJF scheduling:" << endl;
304+
readyQueue.printResult(finalResult);
308305
}
309306
cout << "All the tests have successfully passed!" << endl;
310307
}

0 commit comments

Comments
 (0)