-
Notifications
You must be signed in to change notification settings - Fork 0
/
SSTF.java
65 lines (61 loc) · 938 Bytes
/
SSTF.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import java.util.*;
import java.io.*;
class SSTF
{
public static void main(String args[])
{
int i,n,c,l,m,h,stime=0,t=0,min,v;
int a[]=new int[100];
int f[]=new int[100];
for(i=0;i<100;i++)
f[i]=0;
Scanner s=new Scanner(System.in);
System.out.println("Enter no of disk accesses");
n=s.nextInt();
System.out.println("Enter no of cylinders");
c=s.nextInt();
System.out.println("Enter head position");
h=s.nextInt();
l=h;
System.out.println("Enter accesses");
for(i=0;i<n;i++)
{
a[i]=s.nextInt();
}
System.out.println("Access Sequence is as follows:");
for(v=0;v<n;v++)
{
min=1000;
for(i=0;i<n;i++)
{
if(f[i]==0)
{
if(l>a[i])
{
if(l-a[i]<min)
{
min=l-a[i];
t=i;
}
}
else
{
if(a[i]-l<min)
{
min=a[i]-l;
t=i;
}
}
}
}
f[t]=1;
if(l>a[t])
stime=stime+l-a[t];
else
stime=stime+a[t]-l;
System.out.print(a[t]+" ");
l=a[t];
}
System.out.println("Total seek time is:"+stime);
}
}