It seems reasonable to service all the requests close to the current head position before moving the head far away to service other requests. This assumption is the basis for the shortest-seek-time-first (SSTF) algorithm.
The SSTF algorithm selects the request with the minimum seek time from the current head position.
Since seek time increases with the number of cylinders traversed by the head, SSTF chooses the pending request closest to the current head position.
#include
#include
struct di
{
int num
;
int flag;
};
int main()
{
int i,j,sum=0,n,min,loc,x,y;
struct di d[20];
int disk;
int ar[20],a[20];
clrscr();
printf("enter number of location\t");
scanf("%d",&n);
printf("enter position of head\t");
scanf("%d",&disk);
printf("enter elements of disk queue\n");
for(i=0;i
{
scanf("%d",&d[i].num); d[i]. flag=0;
}
for(i=0;i
{ x=0; min=0;loc=0;
for(j=0;j
{
if(d[j].flag==0)
{
if(x==0)
{
ar[j]=disk-d[j].num;
if(ar[j]<0){ ar[j]=d[j].num-disk;}
min=ar[j];loc=j;x++; }
else
{
ar[j]=disk-d[j].num;
if(ar[j]<0){ ar[j]=d[j].num-disk;}
}
if(min>ar[j]){ min=ar[j]; loc=j;}
}
}
d[loc].flag=1;
a[i]=d[loc].num-disk;
if(a[i]<0){a[i]=disk-d[loc].num;}
disk=d[loc].num;
}
for(i=0;i
{
sum=sum+a[i];
}
printf("\nmovement of total cylinders %d",sum);
getch();
return 0;
}
Output: enter number of location 8 enter position of head 53 enter elements of disk queue 98 183 37 122 14 124 65 67 movement of total cylinders 236