代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
C
】
c++ 磁盘调度算法模拟
作者:
Dezai.CN
/ 发布于
2013/6/20
/
423
for(i = 0; i < MAXQUEUE; i++) { queue[i].go = -1; queue[i].visited = 0; } start = 53; //磁头的初始位置 } //读入磁道号流 void readData() { FILE *fp; char fname[20]; int temp, i; cout << "请输入磁道号流文件名:"; strcpy(fname, "7hard.txt"); cin >> fname; if((fp = fopen(fname, "r")) == NULL) { cout << "错误,文件打不开,请检查文件名:)" << endl; } else { while(!feof(fp)) { fscanf(fp, "%d ", &temp); queue[quantity].go = temp; quantity++; } cout << endl << "---------------------------------------------" << endl; cout << "所读入的磁道号流:"; for(i = 0; i < quantity; i++) { cout << queue[i].go << " "; } cout << endl << "请求数为:" << quantity << endl; } } //FIFO算法 void FIFO() { int i; int total = 0; int current; cout << endl << "---------------------------------------------" << endl; cout << "FIFO算法的访问磁道号顺序流:"; current = start; for(i = 0; i < quantity; i++) { cout << queue[i].go << " "; total += abs(queue[i].go - current); current = queue[i].go; } cout << endl << "磁头移过的柱面数:" << total; } //最短寻道优先调度算法 void shortest() { int i, j, p; int total = 0; int current; cout << endl << "---------------------------------------------" << endl; cout << "最短寻道优先调度算法的访问磁道号顺序流:"; current = start; for(i = 0; i < quantity; i++) { p = 0; while(queue[p].visited != 0) { p++; } for(j = p; j < quantity; j++) { if((queue[j].visited == 0) && (abs(current - queue[p].go) > abs(current - queue[j].go))) { p = j; } } cout << queue[p].go << " "; total += abs(queue[p].go - current); queue[p].visited = 1; current = queue[p].go; } cout << endl << "磁头移过的柱面数:" << total; } //电梯算法 void elevator() { int i, j, p, flag; int total = 0; int current; cout << endl << "---------------------------------------------" << endl; cout << "电梯调度算法" << endl; //磁头初始向里 cout << "磁头初始向里的访问磁道号顺序流:"; current = start; for(i = 0; i < quantity; i++) { flag = 1000; p = -1; for(j = 0; j < quantity; j++) { if((queue[j].visited == 0) && (queue[j].go >= current)) { if(abs(queue[j].go - current) < flag) { p = j; flag = abs(queue[j].go - current); } } } if(p != -1) { cout << queue[p].go << " "; total += abs(queue[p].go - current); current = queue[p].go; queue[p].visited = 1; } else { for(j = 0; j < quantity; j++) { if((queue[j].visited == 0) && (queue[j].go < current)) { if(abs(queue[j].go - current) < flag) { p = j; flag = abs(queue[j].go - current); } } } cout << queue[p].go << " "; total += abs(queue[p].go - current); current = queue[p].go; queue[p].visited = 1; } } cout << endl << "磁头移过的柱面数:" << total << endl; //磁头初始向外 for(i = 0; i < quantity; i++) { queue[i].visited = 0; } total = 0; cout << "磁头初始向外的访问磁道号顺序流:"; current = start; for(i = 0; i < quantity; i++) { flag = 1000; p = -1; for(j = 0; j < quantity; j++) { if((queue[j].visited == 0) && (queue[j].go <= current)) { if(abs(queue[j].go - current) < flag) { p = j; flag = abs(queue[j].go - current); } } } if(p != -1) { cout << queue[p].go << " "; total += abs(queue[p].go - current); current = queue[p].go; queue[p].visited = 1; } else { for(j = 0; j < quantity; j++) { if((queue[j].visited == 0) && (queue[j].go > current)) { if(abs(queue[j].go - current) < flag) { p = j; flag = abs(queue[j].go - current); } } } cout << queue[p].go << " "; total += abs(queue[p].go - current); current = queue[p].go; queue[p].visited = 1; } } cout << endl << "磁头移过的柱面数:" << total; } //显示版权信息函数 void version() { cout << endl << endl; cout << " ┏━━━━━━━━━━━━━━━━━━━━━━━┓" << endl; cout << " ┃ 磁盘调度算法系统 ┃" << endl; cout << " ┠───────────────────────┨" << endl; cout << " ┃ (c)All Right Reserved Neo ┃" << endl; cout << " ┃ sony006@163.com ┃" << endl; cout << " ┃ version 2004 build 1122 ┃" << endl; cout << " ┗━━━━━━━━━━━━━━━━━━━━━━━┛" << endl; cout << endl << endl; } void main() { int i; version(); initial(); readData(); FIFO(); shortest(); for(i = 0; i < quantity; i++) { queue[i].visited = 0; } elevator(); }
试试其它关键字
磁盘调度
同语言下
.
获取手机通讯录 iOS去除数字以外的所有字符
.
异步加载音乐等资源
.
交通罚单管理系统
.
freemark实现,简单的替换
.
计算斐波那契数列
.
base64解码 包括解码长度
.
图像显示
.
冒泡排序
.
输入十进制数,输出指定进制
.
链式栈
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
Dezai.CN
贡献的其它代码
(
4037
)
.
多线程Socket服务器模块
.
生成随机密码
.
清除浮动样式
.
弹出窗口居中
.
抓取url的函数
.
使用base HTTP验证
.
div模拟iframe嵌入效果
.
通过header转向的方法
.
Session操作类
.
执行sqlite输入插入操作后获得自动编号的ID
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3