/* ================================================================================
* * *
* * * Filename: sstf.c
* * * Created: Tuesday 24 March 2015
* * * Compiler: gcc
* * * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * * Organization: SCIS,University of Hyderabad
* * *
* ===============================================================================*/
#include<stdio.h>
#include<stdlib.h>
void main()
{
int pos,size,diff = 1000,loc,i,j;
printf("========================================================");
printf("\nEnter the current head position:\n");
scanf("%d",&pos);
printf("\nEnter the number of DISK position:\n");
scanf("%d",&size);
int req[size];
printf("========================================================");
printf("\nEnter the location position to schedule:\n");
for(i=0;i<size;i++)
scanf("%d",&req[i]);
printf("========================================================");
printf("\nSSTF requests served in the order as follows :\n");
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(req[j] == -1)
continue;
else
{
if(abs(pos - req[j]) <= diff)
{
diff = abs(pos - req[j]);
loc = j;
}
}
}
diff = 1000;
printf("%d ",req[loc]);
pos = req[loc];
req[loc] = -1;
}
printf("\n========================================================");
printf("\n");
}
* * *
* * * Filename: sstf.c
* * * Created: Tuesday 24 March 2015
* * * Compiler: gcc
* * * Author: Manoj Kumar Patra,manojpatra.sit@gmail.com
* * * Organization: SCIS,University of Hyderabad
* * *
* ===============================================================================*/
#include<stdio.h>
#include<stdlib.h>
void main()
{
int pos,size,diff = 1000,loc,i,j;
printf("========================================================");
printf("\nEnter the current head position:\n");
scanf("%d",&pos);
printf("\nEnter the number of DISK position:\n");
scanf("%d",&size);
int req[size];
printf("========================================================");
printf("\nEnter the location position to schedule:\n");
for(i=0;i<size;i++)
scanf("%d",&req[i]);
printf("========================================================");
printf("\nSSTF requests served in the order as follows :\n");
for(i=0;i<size;i++)
{
for(j=0;j<size;j++)
{
if(req[j] == -1)
continue;
else
{
if(abs(pos - req[j]) <= diff)
{
diff = abs(pos - req[j]);
loc = j;
}
}
}
diff = 1000;
printf("%d ",req[loc]);
pos = req[loc];
req[loc] = -1;
}
printf("\n========================================================");
printf("\n");
}
No comments:
Post a Comment