2
1

added sjf code

This commit is contained in:
Tanmay 2024-07-27 11:18:03 +05:30
parent fb0e0e15df
commit 81c27ea1b1
2 changed files with 70 additions and 0 deletions

View File

@ -0,0 +1,65 @@
#include<iostream>
using namespace std;
struct sjf{
int burst, arrival, id;
bool active;
};
sjf meh[30];
class lesgo{
public:
int n;
void sjfIn(){
cout<<"\nEnter number of processes: ";
cin>>n;
for(int i = 0; i < n; i++){
cout<<"\nEnter arrival time of P"<<i<<": ";
cin>>meh[i].arrival;
cout<<"\nEnter burst time of P"<<i<<": ";
cin>>meh[i].burst;
meh[i].id = i;
meh[i].active = false;
}
cout<<"\n | Arrival | Burst\n";
for(int j = 0; j < n; j++) {
cout<<"P"<<j<<"| "<<meh[j].arrival<<" | "<<meh[j].burst<<"\n";
}
}
void sjfProcess(){
int k = 0;
int completed = 0;
cout<<"\nSequence of processes is: ";
while(completed < n){
int burst1 = 999;
int iddd = -1;
for(int i = 0; i < n; i++){
if(meh[i].arrival <= k && meh[i].burst > 0){
if(meh[i].burst < burst1){
burst1 = meh[i].burst;
iddd = i;
}
}
}
if(iddd != -1){
cout<<"P"<<iddd<<" ";
meh[iddd].burst--;
k++;
if(meh[iddd].burst == 0){
completed++;
}
} else{
k++;
}
}
}
};
int main(){
lesgo obj;
obj.sjfIn();
obj.sjfProcess();
return 0;
}

View File

@ -0,0 +1,5 @@
### Codes
##### Group B
5. [Assignment - 5]()
- [SJF (Preemptive)]()