From 40d663d358cf04ff63a64827c3afa00b5b421c94 Mon Sep 17 00:00:00 2001 From: Pratyush219 Date: Wed, 13 Oct 2021 12:01:00 +0530 Subject: [PATCH] Replaced time(0) with time(nullptr) --- cpu_scheduling_algorithms/fcfs_scheduling.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/cpu_scheduling_algorithms/fcfs_scheduling.cpp b/cpu_scheduling_algorithms/fcfs_scheduling.cpp index 0d55305df..bc411ca9b 100644 --- a/cpu_scheduling_algorithms/fcfs_scheduling.cpp +++ b/cpu_scheduling_algorithms/fcfs_scheduling.cpp @@ -130,7 +130,7 @@ class FCFS{ /** * @brief Algorithm for scheduling CPU processes according to the First Come First Serve(FCFS) scheduling algorithm. * - * @description FCFS is a non-preemptive algorithm in which the process which arrives first gets executed first. If two or + * @details FCFS is a non-preemptive algorithm in which the process which arrives first gets executed first. If two or * more processes arrive together then the process with smaller process ID runs first (each process has a unique proces ID). * * I used a min priority queue of tuples to accomplish this task. The processes are ordered by their arrival times. If arrival @@ -196,9 +196,16 @@ class FCFS{ }; +/** + * @brief function to be used for testing purposes. This function guarantees the correct solution for FCFS scheduling algorithm. + * @param input the input data + * @details Sorts the input vector according to arrival time. Processes whose arrival times are same get sorted according to process ID + * For each process, completion time, turnaround time and completion time are calculated, inserted in a tuple, which is added to the vector result. + * @returns a vector of tuples consisting of process ID, arrival time, burst time, completion time, turnaround time and waiting time for each process. +*/ template -vector> get_final_status(vector>& input){ - sort(input.begin(), input.end(), sortcol); +vector> get_final_status(vector> input){ + sort(input.begin(), input.end(), sortcol); vector> result(input.size()); double timeElapsed = 0; for(size_t i{}; i < input.size(); i++){ @@ -226,16 +233,16 @@ vector> get_final_status(vector readyQueue; vector> input(n); for(int i{}; i < n; i++){ get<0>(input[i]) = i; - srand(time(0)); + srand(time(nullptr)); get<1>(input[i]) = 1 + rand()%10000; - srand(time(0)); + srand(time(nullptr)); get<2>(input[i]) = 1 + rand()%10000; }