Sjf
Thu Apr 18 2024 07:29:38 GMT+0000 (Coordinated Universal Time)
Saved by
@viinod07
#include<stdio.h>
#include<stdlib.h>
int main()
{
int r[100],i,n,Tst=0,initial,count=0;
printf("Enter the number of Requests\n");
scanf("%d",&n);
printf("Enter the Requests sequence\n");
for(i=0;i<n;i++)
scanf("%d",&r[i]);
printf("Enter initial head position\n");
scanf("%d",&initial);
// logic for sstf disk scheduling
/* loop will execute until all process is completed*/
while(count!=n)
{
int min=1000,d,index;
for(i=0;i<n;i++)
{
d=abs(r[i]-initial);
if(min>d)
{
min=d;
index=i;
}
}
Tst=Tst+min;
initial=r[index];
// 1000 is for max
// you can use any number
r[index]=1000;
count++;
}
printf("Total head movement is %d",Tst);
return 0;
}
content_copyCOPY
Comments