栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

武汉理工大学操作系统课内实验二

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

武汉理工大学操作系统课内实验二

一、前言

        本文内容:武汉理工大学操作系统的第二次课内实验

        开发环境:IntelliJ IDEA2021.3

二、实验要求 1.实验内容

        模拟实现磁盘调度

2.实验要求

        (1)选择1~3种磁盘调度算法(先来先服务算法、最短寻道时间优先算法、电梯算法)模拟                  实现磁盘调度;

        (2)能够输入当前磁头的位置磁头移动方向、磁头访问请求序列等;

        (3)计算磁头移动的总磁道数;

        (4)能够显示磁盘调度结果(磁头依次访问的磁道顺序)

三、实验原理与设计 1.算法原理

        (1)先来先服务算法:按先来后到次序服务。这个算法实际上不考虑访问者要求访问的物理                   位置,只考虑访问者提出访问的先后顺序。

        (2)最短寻道时间优先算法:该算法从等待访问者中挑选距离最近的访问请求进行访问,而                   不考虑访问请求的先后顺序。

        (3)电梯算法:该算法是从磁头位置开始,先选择大于或小于磁头作为移动方向,优先完成                   该方向上的申请序列,然后再完成另一个方向上的申请序列。

2.主要仪器设备及耗材

        装有windos10系统的PC机一台;

        Java JDK17

        IntelliJ IDEA 2021.3

3.算法设计
  
    public void firstComeFirstServe(){
        Scanner scan = new Scanner(System.in);
        System.out.println("磁头位置为:");
        int head = scan.nextInt();
        visitList[0] = head;
        System.arraycopy(requestList, 0, visitList, 1, requestList.length);
        System.out.println("先来先服务:");
        showPath();
        showSum();
    }
    
    public void  minSeekTime(){
        Scanner scan = new Scanner(System.in);
        System.out.println("磁头位置为:");
        int head = scan.nextInt();
        visitList[0] = head;
        linkedList list = new linkedList<>();
        for (int j : requestList) {
            list.add(j);
        }
        for(int i = 1 ;i < visitList.length;i++){
            visitList[i] = findNear(list,head);
        }
        System.out.println("最短寻道时间优先:");
        showPath();
        showSum();
    }
    public int findNear(linkedListlist ,int head){
        int index = 0;
        int min = 1000;
        for(int i =0;i< list.size();i++){
            if(Math.abs(head- list.get(i)) 
 public void theElevatorAlgorithm()                                                                                                                                                                                                                                                                                                                                                  {
        
        Scanner scan = new Scanner(System.in);
        System.out.println("磁头位置为:");
        int head = scan.nextInt();
        visitList[0] = head;
        
        PriorityQueue compareSmall = new PriorityQueue<>(10, new Comparator<>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;
            }
        });
        
        PriorityQueue compareBig = new PriorityQueue<>(10);
        
        for (int j : requestList) {
            if (j > head) {
                compareBig.add(j);
            } else if (j < head) {
                compareSmall.add(j);
            }
        }
        int index = 1;
        int command = scan.nextInt();
        switch (command){
            //选择‘1’即从磁头位置向右扫描
            case 1 :{
                while (!compareBig.isEmpty()){
                    visitList[index++] = compareBig.poll();
                }
                while(!compareSmall.isEmpty()){
                    visitList[index++] = compareSmall.poll();
                }
                break;
            }
            //选择‘2’即从磁头位置向左扫描
            case 2 :{
                while(!compareSmall.isEmpty()) {
                    visitList[index++] = compareSmall.poll();
                }
                while (!compareBig.isEmpty()){
                    visitList[index++] = compareBig.poll();
                }
                break;
            }
            default:{
                System.out.println("输入错误!!!");
            }
        }
        System.out.println("电梯算法:");
        showPath();
        showSum();
    }
四、源码

        链接:https://pan.baidu.com/s/1k95pNoSx3k6NoHoO5nRntw 
        提取码:jiei 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/686293.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号