简体   繁体   English

使用循环算法计算所需时间

[英]Using round robin algorithm to calculate time needed

Maybe someone out there is feeling friendly and would find this brain teaser interesting.. but I feel like maybe I started confusing myself. 也许有人在外面感到友善,会觉得这个脑筋急转弯很有趣..但是我感觉也许我开始迷惑了自己。

The object of this is to calculate, using the round robin algorithm, the time it would take for all of the processes to complete. 目的是使用循环算法来计算完成所有过程所需的时间。 I have it prompt the user for the time quantum, and then how many processes it would like to calculate. 我让它提示用户输入时间量,然后提示用户要计算多少个进程。 From there, I throw a for statement based on however many processes there are to assign the process arival time and the burst time. 从那里,我基于所有要分配进程到达时间和突发时间的进程抛出一个for语句。

For those who arent familiar, the time quantum is how many cycles it will process before it switches to the next, the burst is how many cycles it takes to complete that process, and of course the arival time is how many cycles have completed before it arives. 对于那些不熟悉的人来说,时间量是指切换到下一个之前将处理的周期数,突发是完成该过程所需的周期数,当然到达时间是指完成该过程之前已完成的周期数。到达。 Simple algorithm, but it's to show how CPU's schedule. 简单的算法,但是它显示了CPU的调度方式。 IF ANYONE COULD HELP AT ALL THAT WOULD BE FANTASTIC! 如果有人可以帮助您,那将是不可思议的! I'm so lost. 我迷路了 I wanted to do this in C#, but my programming skills are less than sufficent in C# for that. 我想在C#中做到这一点,但是我的编程技能不足以在C#中做到这一点。

The two problems I am having are in my if statements, I started to lose myself, and for whatever reason, it gives me an error when compiling with dif < parrive.get[ii] or dif < parrive.get(ii) OR even assigning parrive.get[ii] to another variable at the beginning of my if statements and using another variable(as shown)... 我遇到的两个问题是我的if语句,我开始迷失自我,无论出于何种原因,在使用dif <parrive.get [ii]或dif <parrive.get(ii)或什至进行编译时,都会给我一个错误在我的if语句的开头将parrive.get [ii]分配给另一个变量,并使用另一个变量(如图所示)...

import java.io.*;
import java.util.*;

public class Thread{       

    public Thread() {
        inputexecute();
    }

    public void inputexecute(){

        Scanner x = new Scanner(System.in);
        int xx = 0;

        String choice = null;
        ArrayList parrive = new ArrayList();
        ArrayList pburst = new ArrayList();

        while (true){
            System.out.println("Enter the time quantum: ");
            int quant = x.nextInt();
            System.out.println("Enter the number of processes: ");
            int pnum = x.nextInt();

            for( int i=0; i<pnum; i++)
            {
                System.out.println("Enter the arival for p"+i+": ");
                int arrive = x.nextInt();
                parrive.add(arrive);

                System.out.println("Enter the burst time: ");
                int burst = x.nextInt();
                pburst.add(burst);    


            }

            int dif;
            for(int ii=0; ii < pnum; ii++)
            {
                int asw == parrive.get[ii];

                if (asw < quant)
                {
                    dif = quant - asw;
                }                    
                if (quant < asw)
                {
                    asw = asw - quant;
                }
                if (dif > 0)
                {

                }
            }
        } /* end while*/
    } /* end exec input*/
} /* class thread */

Your error is that you are using equality operator (==) instead of assignment 您的错误是您使用等于运算符(==)而不是赋值

                            int asw == parrive.get[ii];

should be 应该

                            int asw = parrive.get[ii];

The way I would write it 我写的方式

List<Integer> parrive = new ArrayList<Integer>();

for(int asw: parrive) {
    int dif = Math.abs(asw - quant);
    if (dif == 0) continue;
    // if dif > 0

}

I am assuming 我假设

asw = asw - quant;

should be 应该

dif = asw - quant;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM