SSTF Disk Scheduling Algorithm
Created By: Pirate
*/
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
int queue[100],t[100],head,seek=0,n,i,j,temp;
float avg;
// clrscr();
printf("*** SSTF Disk Scheduling Algorithm ***\n");
printf("Enter the size of Queue\t");
scanf("%d",&n);
printf("Enter the Queue\t");
for(i=0;i<n;i++)
{
scanf("%d",&queue[i]);
}
printf("Enter the initial head position\t");
scanf("%d",&head);
for(i=1;i<n;i++)
t[i]=abs(head-queue[i]);
for(i=0;i<n;i++)
{
for(j=i+1;j<n;j++)
{
if(t[i]>t[j])
{
temp=t[i];
t[i]=t[j];
t[j]=temp;
temp=queue[i];
queue[i]=queue[j];
queue[j]=temp;
}
}
}
for(i=1;i<n-1;i++)
{
seek=seek+abs(head-queue[i]);
head=queue[i];
}
printf("\nTotal Seek Time is%d\t",seek);
avg=seek/(float)n;
printf("\nAverage Seek Time is %f\t",avg);
getch();
}
Output
Hi, Nice Post. you raise some really great points. Thanks for sharing.Scheduling Software
ReplyDeleteHi,Thank you.
DeleteTry giving other inputs , this code won't show the proper result.
ReplyDeletewhat are your input? tell.
Deletedidnt get the correct output...try to check the code or u might have posted a wrong code
ReplyDeleteTell me your input data. I'll check.
Delete98
Delete58
55
39
38
18
150
160
184
head initial 100
output avg seek 27.5
Please run program correctly. Output is 50.0004 ave seek time.
Deletewrong result.... what about t[0]
ReplyDeletehere t[0] will give garbage value.
ReplyDeletewrong ans
ReplyDeletethis program needs one correction
Deletefor(i=1;i<n;i++)
instead of
for(i=1;i<n-1;i++)
seek=seek+abs(head-queue[i]);
head=queue[i];
Nice
ReplyDeleteThere is another correction needed:
ReplyDeletefor(i=0;i<n;i++)
t[i]=abs(head-queue[i]);
instead of
for(i=1;i<n;i++)
t[i]=abs(head-queue[i]);
The way it was, the first value of the queue is not going to be properly evaluated in some cases.
thanks i'll look into it.
DeleteOf course this would give wrong ans,programmer using zero based indexing while taking input and starting from t[1] while taking abs difference .
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDelete