From 0fa5d15da6f03db1108b1d4e582e8d23d1dbb1a4 Mon Sep 17 00:00:00 2001 From: Tanmay Date: Wed, 6 Nov 2024 08:29:55 +0530 Subject: [PATCH] corrected sjf --- .../Assignment - 5/SJF (Preemptive).cpp | 107 ++++++++---------- 1 file changed, 46 insertions(+), 61 deletions(-) diff --git a/Codes/Group B/Assignment - 5/SJF (Preemptive).cpp b/Codes/Group B/Assignment - 5/SJF (Preemptive).cpp index afa711a..01b02aa 100644 --- a/Codes/Group B/Assignment - 5/SJF (Preemptive).cpp +++ b/Codes/Group B/Assignment - 5/SJF (Preemptive).cpp @@ -1,64 +1,52 @@ -#include -#include // for INT_MAX +#include using namespace std; struct sjf{ - int burst, arrival, id, completion, waiting, turnaround, response; - bool active; + int id, arr, bur, comp, turn, wait, orgBur; }; - sjf meh[30]; -class lesgo{ +class SJF{ public: int n; - - void sjfIn(){ - cout<<"\nEnter number of processes: "; + void getIn() + { + cout<<"Enter number of processes: "; cin>>n; - for(int i = 1; i <= n; i++){ - cout<<"\nEnter arrival time of P"<>meh[i].arrival; - cout<<"\nEnter burst time of P"<>meh[i].burst; + for(int i = 0; i < n; i++){ + cout<<"\nEnter arrival time for process "<>meh[i].arr; + cout<<"Enter burst time for process "<>meh[i].bur; + meh[i].orgBur = meh[i].bur; meh[i].id = i; - meh[i].active = false; - } - cout<<"\n | Arrival | Burst\n"; - for(int j = 1; j <= n; j++) { - cout<<"P"< 0){ - if(meh[i].burst < burst1){ - burst1 = meh[i].burst; - iddd = i; + int burst = 999; + int idd = -1; + for(int i = 0; i < n; i++){ + if(meh[i].arr <= k && meh[i].bur > 0){ + if(meh[i].bur < burst){ + burst = meh[i].bur; + idd = i; } } } - if(iddd != -1){ - // Mark the process as active - if(!meh[iddd].active) { - meh[iddd].response = k - meh[iddd].arrival; - meh[iddd].active = true; - } - - cout<<"P"<