Thursday 21 March 2013

sstf disk scheduling


#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int max,min,disk,mark[100],q[100],rear=0,size,head,seek;
void ins();
void dis();
void sstf();
void fmaxmin();
main()
{
int i,ch;
printf("\nEnter the size of the disk (in tracks) : ");
scanf("%d",&disk);
printf("\nEnter the current position of the disk head : ");
scanf("%d",&head);
printf("\nEnter the number of requests : ");
scanf("%d",&size);
if(size!= 0)
printf("\nEnter the requests - : \n\n");
else
{
printf("No requests to be made ");
return;
}
for(i=1;rear<=size;i++)
{
ins();
mark[i] = 0;
}
fmaxmin();
q[0] = head;
printf("\n\n\t\t\t\tDISK SCHEDULING\n\n");
head = q[0];
seek = 0;
sstf();
getch();
}
void ins()
{
int i;
rear++;
if(rear<=size)
{
printf("Enter the request %d to track no. : ",rear);
scanf("%d",&i);
}
if(i>disk)
{
printf("\nEnter valid track request\n\n");
rear--;
}
else
q[rear] = i;
}
void dis()
{
int i;
for(i=1;i<=size;i++)
printf("%d\t",q[i]);
}
void sstf()
{
int low = disk,j,flag;
for(j=1;j<=size;j++)
{
if(abs(head-q[j]) < low && mark[j] == 0)
{
low = abs(head-q[j]);
flag = j;
}
}
mark[flag] = 1;
printf("\nHead moves from %d to %d...",head,q[flag]);
head = q[flag];
seek += low;
}
void fmaxmin()
{
int i;
for(i = 1;i<=size;i++)
{
if(q[i]>max)
max = q[i];
if(q[i]<min)
min = q[i];
}
}

No comments:

Post a Comment

Have some problem with this code? or Request the code you want if you cant find it in Blog Archive.