📄 sjf_norm.cpp
字号:
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int bt[10][2];
int i=0,j,k,l;
float avg;
int sum=0;
int temp,temp1;
char choice;
for(l=0;l<10;l++)
bt[l][1]=l+1;
cout<<"\n\n\t\tShortest Job First (Non-Preemptive) Scheduling Algorithm";
do
{
cout<<"\nEnter burst time for Process "<<i+1<<" : ";
cin>>bt[i][0];
cout<<"Want to continue (Y/N)? : ";
cin>>choice;
i++;
}while(choice=='y'||choice=='Y');
for(j=0;j<i-1;j++)
{
for(k=0;k<i-1-j;k++)
{
if(bt[k][0]>bt[k+1][0])
{
temp=bt[k][0];
temp1=bt[k][1];
bt[k][0]=bt[k+1][0];
bt[k][1]=bt[k+1][1];
bt[k+1][0]=temp;
bt[k+1][1]=temp1;
}
}
}
cout<<"Process execution sequence :: ";
for(j=0;j<i;j++)
{ cout<<"\nProcess "<<bt[j][1]<<" Executing.";
for(k=0;k<j;k++)
sum=sum+bt[k][0];
}
avg=((float)sum)/i;
cout<<"\n\n\t\tAverage waiting time is :: "<<avg;
getch();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -