磁盘调度 C语言实现
来源:互联网 发布:淘宝宝贝图片下载器 编辑:程序博客网 时间:2024/06/14 16:20
#include <iostream>#include <cstdlib>#include <stdio.h>using namespace std;void FIFO(int a[],int n){ int sum = 0; int i,j,now; float avg; cout << "请输入当前的磁道号:"; cin >> now; cout << "磁盘调度顺序为:" << endl; for(i = 0; i < n; i++) { cout << a[i] <<" "; } cout << endl; sum += abs(a[0] - now); cout << "从当前位置到第1个磁道移动的磁道数为:" << sum << endl; for(i = 0,j = 1; j < n; i++,j++) { sum += abs(a[j] - a[i]); cout << "从第" << i+1 << "个磁道到第" << j+1 << "个磁道的移动距离为:" << abs(a[j] - a[i]) << endl; } cout << endl; cout << "移动的总磁道数为:" << sum <<endl; avg = sum * 1.0 / n; cout << "平均寻道长度为:" << avg << endl;}void SSTF(int a[],int n){ int temp; int now,L,r; int j,i; int k = 1; int sum = 0; float AVG; for(i = 0; i < n; i++) for(j = i + 1; j < n; j++) { if(a[i] > a[j]) { temp = a[i]; a[i] = a[j]; a[j] = temp; } } cout <<"按递增顺序排好的磁道:" << endl; for(i = 0; i < n; i++) cout << a[i] << " "; cout << endl; cout << "请输入当前的磁道号:"; cin >> now; cout << "磁盘调度顺序为:" << endl; if(now >= a[n-1]) { for(i = n-1; i >= 0; i--) cout << a[i] << " " << endl; cout << "从当前位置到第1个磁道移动的磁道数为:" << now - a[n-1] << endl; for(i = 0,j = 1; j < n; i++,j++) cout << "从第" << i+1 << "个磁道到第" << j+1 << "个磁道的移动距离为:" << abs(a[j] - a[i]) << endl; sum = now - a[0]; } else if(now < a[0]) { for(i = 0; i < n; i++) cout << a[i] << " " << endl; cout << "从当前位置到第1个磁道移动的磁道数为:" << a[0] - now << endl; for(i = 0,j = 1; j < n; i++,j++) cout << "从第" << i+1 << "个磁道到第" << j+1 << "个磁道的移动距离为:" << abs(a[j] - a[i]) << endl; sum = a[n-1] - now;//同上面 } else { while(a[k] < now) k++; L = k -1; r = k; while((L >= 0) && (r < n)) { if((now - a[L]) <= (a[r] - now)) { cout << a[L] << " "; sum += now - a[L]; now = a[L]; L--; } else { cout << a[r] << " "; sum += a[r] - now; now = a[r]; r++; } } if(L = -1) { for(j = r; j < n; j++) cout << a[j] << " "; sum += a[n-1] -a[0]; } if(r == n) { for(j = k - 1; j > -1; j--) cout << a[j] << " "; sum += a[n-1] - a[0]; } } cout << endl; cout << "移动的总磁道数:" << sum <<endl; AVG = sum * 1.0 / n; cout << "平均寻道长度为:" << AVG << endl;}int main(){ int n; int s; int i; cout << "请输入磁道个数:" << endl; cin >> n; int *a = new int[n]; for(i = 0;i < n; i++) { cout << "请输入第" << i+1 << "个磁道号:"; cin >> a[i]; } cout << endl; while(1) { cout << endl; cout << "1:先来先服务算法:" << endl; cout << "2:最短寻道时间算法:" << endl; cout << "0:退出" << endl; cout << endl; cout << "请选择功能号:"; cin >> s; switch(s) { case 0:exit(0);break; case 1:FIFO(a,n);break; case 2:SSTF(a,n);break; } } return 0;}
阅读全文
0 0
- 磁盘调度 C语言实现
- C语言 磁盘调度模拟
- 【操作系统】C语言模拟操作系统实现磁盘调度算法——电梯调度算法
- CSCAN调度算法(C语言描述)磁盘
- 调度算法 SCAN 磁盘(C语言描述)
- 磁盘调度算法-java实现
- 磁盘调度算法 C++实现
- Java实现磁盘调度算法
- C语言线程调度
- C语言实现文件复制 磁盘遍历 文件查找
- 多级反馈队列调度算法 C语言模拟实现
- 进程的优先调度算法的c语言实现
- C语言实现多级反馈队列调度算法
- 时间片轮转调度算法的C语言模拟实现
- 作业调度之先来先服务算法C语言实现
- 电梯调度的C语言实现(vc可正常运行)
- 处理机调度算法C语言实现(注释得当!!)
- 链表实现磁盘调度算法
- JVM性能监控和故障处理工具
- HTTP协议
- FreeRTOS学习1--任务挂起与恢复
- CSUOJ nineteen thirteen One big silly dragon gives gifts out 线段树 二分 转化
- java中SocktTCP相关案例
- 磁盘调度 C语言实现
- 【LeetCode】48. Rotate Image
- POJ 1923 Fourier's Lines 笔记
- 批量处理(批量查找)的简单应用--xargs、exec、grep
- [LeetCode] Arithmetic Slices II
- 我的博客搬家啦
- MFC BEGIN_MESSAGE_MAP()
- 第五章 画蛇添足
- 我的博客即将入驻“云栖社区”,诚邀技术同仁一同入驻。