SCAN扫描算法
来源:互联网 发布:一个简单的php程序 编辑:程序博客网 时间:2024/06/17 00:08
该算法不仅考虑到欲访问的磁道与当前磁道的距离,更优先考虑的是磁道的当前移动方向
#include <malloc.h> #include<stdio.h> #include<math.h> #include <limits.h> typedef struct track{ int column; struct track *next; }node; int location; /*当前磁头位置*/ int sum_move; /*磁头移动总磁道数*/ float ave_move; /*磁头移动平均磁道数*/ int direction; /*磁头移动的方向:direction=1 表示从里向外移动,direction=-1 表示从 外向里移动*/ int found_node(node *head) /*找到离当前磁头最近且与direction 同方向的磁道*/ { node *p,*t; int panduan,truecol=0,jiange=10000; p=head; t=head; while(p&&t){ if(direction==1){ while(p){ if(p->column>=location) { panduan=p->column-location; if(panduan<jiange) { truecol=p->column; jiange=panduan; } } p=p->next; } if(truecol==0){ direction=-1; } } if(direction==-1){ while(t){ if(t->column<location) { panduan=location-t->column; if(panduan<jiange) { truecol=t->column; jiange=panduan; } } t=t->next; } if(truecol==0){ direction=1; } }} sum_move+=jiange; location=truecol; printf("%d ",truecol); return truecol;} node *SCAN(node *head) /*调用found_node 找到满足条件的磁道,并从head 链表中删除该结点*/ { node *pre,*p; int a; a=found_node(head); pre=NULL; p=head; while(p&&(p->column!=a)){ pre=p; p=p->next; } if(p){ if(!pre) {head=head->next;} else pre->next=p->next; } return head;} void main() { int i,num,disk_length; node *head,*p1,*p2; head=NULL; printf("输入磁盘柱面总数:\n"); scanf("%d",&disk_length); printf("输入磁盘读写请求总数:\n"); scanf("%d",&num); printf("输入磁盘读写请求柱面号序列:\n"); for(i=1;i<=num;i++) { p1=(node *)malloc(sizeof(node)); scanf("%d",&p1->column); if(head==NULL){ head=p1; p2=p1; } else{ p2->next=p1; p2=p1; } p2->next=NULL; } printf("输入磁盘当前位置为:\n"); scanf("%d",&location); printf("输入磁盘移动方向(1 表示从里向外移动,-1 表示从外向里移动):\n"); scanf("%d",&direction); printf("\n依次访问的柱面号为:\n"); sum_move=0; for(i=1;i<=num;i++) { SCAN(head); } ave_move=(float)sum_move/num; printf("\n总的移动柱面次数为:%d\n",sum_move); printf("\n平均移动次数为:%.2f\n",ave_move);}
阅读全文
0 0
- SCAN扫描算法
- SCAN扫描算法 java实现
- Graham扫描算法(Graham Scan Algorithm)
- HBase扫描操作Scan
- scan算法
- Scan 算法
- 操作系统实验之磁盘调度算法模拟(最短寻道时间优先SSTF 和 扫描算法SCAN)
- 什么是边界扫描(boundary scan)?
- spring component-scan 包扫描
- ARP扫描工具arp-scan
- SQL Server中扫描(scan)和查找(seek)这两种算法的区别
- 一个简单的页面扫描程序Scan
- 综合扫描工具x-scan使用教程
- openwrt iw 扫描AP iw wlan0 scan
- 怎样扫描图片how to scan images
- spring扫描注解工具类scan
- spring组件扫描<context:component-scan/>详解
- 用arp-scan扫描局域网IP地址
- ORACLE-SQL编写规范(详细解释)
- Java技术——Java泛型详解
- 前中遍历创建二叉树
- Python 3爬虫网易云(四)—— 正则表达式上篇之匹配法则
- Ubuntu截图快捷键设置
- SCAN扫描算法
- 第三周项目一 顺序表的基本运算
- java作用域
- 设计模式_ 代理模式(11)
- 9月第二周
- Maven学习笔记(四)-----生命周期|POM常用元素介绍
- hihoCoder1403(后缀数组 + 二分)
- Codeforces 758C- Unfair Poll
- 微信公众号开发(十二)OAuth2.0网页授权