移动臂调度算法java
时间: 2023-11-25 07:51:48 浏览: 90
以下是移动臂调度算法的Java实现:
```java
public class DiskScheduling {
static int maxsize = 100;
static int Disc[] = new int[maxsize];
static int n; static int cur = 50;
static int sum = 0;
public static void main(String[] args) {
init();
SSTF();
}
// 初始化请求序列
public static void init() {
System.out.println("请输入请求序列长度:");
Scanner sc = new Scanner(System.in);
n = sc.nextInt();
System.out.println("请输入请求序列:");
for (int i = 0; i < n; i++) {
Disc[i] = sc.nextInt();
}
}
// 最短寻找时间优先算法
public static void SSTF() {
System.out.println("---------最短寻找时间优先算法---------");
int[] flag = new int[n];
int k = 0;
while (k < n) {
int min = Integer.MAX_VALUE;
int index = -1;
for (int i = 0; i < n; i++) {
if (flag[i] == 0) {
int diff = Math.abs(Disc[i] - cur);
if (diff < min) {
min = diff;
index = i;
}
}
}
flag[index] = 1;
sum += min;
cur = Disc[index];
k++;
}
System.out.println("移动磁头的总寻道长度为:" + sum);
}
}
```
阅读全文