Monday, 1 February 2016

C++ Program For PRIORITY Scheduling Algorithm In Linux

//Ghanendra Yadav
#include<iostream>
using namespace std;

struct process
{
int cbt;
int priority;
int flag;
};
int main(){
int p, minp, index, sum=0;
cout<<"\nEnter Number of Process";
cin>>p;
process pr[p];
int *bt=new int[p+1];
int *wt =new int[p];
int *tat=new int[p];
cout<<"\nEnter CBT and its priority";
for(int i=0; i<p; i++){
cin>>pr[i].cbt>>pr[i].priority;
pr[i].flag=1;
}
cout<<"\n------------------------------------------------------\n";

for(int i=0; i<p; i++){
//cout<<pr[i].cbt<<"  "<<pr[i].priority;
minp=100;
for(int j=0; j<p; j++){
if(pr[j].flag==1 && pr[j].priority<minp){
minp=pr[j].priority;
index=j;
}
}
cout<<"p"<<index+1<<"\t";
bt[i]=pr[index].cbt;//<<"  "<<pr[index].priority<<endl;
pr[index].flag=0;
wt[i]=sum;
sum+=pr[index].cbt;
tat[i]=sum;
}
cout<<endl;
for(int i=0; i<p; i++){
cout<<bt[i]<<"\t";
}

return 0;
}

Output:-


No comments:
Write comments

Recommended Posts × +