public static string FCFS(queue q,queuefinish p)
        {
            string msg=null;
            if (q.length > 0)
            {
                if (q.now_process == null)
                {
                    q.now_process = q.del_first();
                }
                if (q.now_process.period_need_left <= 0)
                {
                    msg = "完成job" + q.now_process.num.ToString()+"\r\n";
                    q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                    p.wait[p.length++] = q.now_process;
                    q.now_process = q.del_first();
                    return msg;

                }
                else return null;
            }
            else if (q.now_process != null && q.now_process.period_need_left <= 0)
            {
                msg = "完成job" + q.now_process.num+"\r\n";
                q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                p.wait[p.length++] = q.now_process;
                q.now_process = null;
                return msg;
            }
            else return null;
        }
        public Form1()
        {
            InitializeComponent();

            qwait = new queue();
            qfinish = new queuefinish();
            time_pass = 0;
            time_interval = 2;
        }
        public static string refresh(queue q)
        {
            int i = 0;
            string msg = "等待的任务:\r\n";
            for (; i < q.length ;i++ )
            {
                    msg += "job" + q.wait[i].num.ToString() + "\r\n";
                    q.wait[i].wait_already++;

            }
            if (q.now_process != null)
            {
                q.now_process.period_need_left--;
                return msg += "正在执行:job" + q.now_process.num.ToString() + "\r\n";
            }
            else return null;
        }
        public static string HRRF(queue q,queuefinish p)
        {
            //剥夺式最高响应比
                /*string msg;
                process p1;
                if (q.length > 0)
                {
                    if (q.now_process == null)
                    {
                        q.now_process = q.del_highest_response_ratio();

                    }
                    if (q.now_process.period_need_left <= 0)
                    {
                        msg = "完成job" + q.now_process.num.ToString() + "\r\n";
                        q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                        p.wait[p.length++] = q.now_process;
                        q.now_process = q.del_highest_response_ratio();

                        return msg;

                    }
                    else if ((q.now_process.wait_already/q.now_process._need_period_num+1) < ((p1 = (q.length > 0 ? q.del_highest_response_ratio() : q.now_process)).wait_already/p1._need_period_num+1))
                    {
                        q.add(q.now_process);
                        q.now_process = p1;
                        return null;
                    }

                    else
                    {

                        if (q.now_process != p1) q.add(p1);
                        return null;
                    }
                }
                else if (q.now_process != null && q.now_process.period_need_left <= 0)
                {
                    msg = "完成job" + q.now_process.num + "\r\n";
                    q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                    p.wait[p.length++] = q.now_process;
                    q.now_process = null;
                    return msg;
                }
                else return null;*/

            //非剥夺式最高响应比
            string msg;
            if (q.length > 0)
            {
                if (q.now_process == null)
                {
                    q.now_process = q.del_highest_response_ratio();

                }
                if (q.now_process.period_need_left <= 0)
                {
                    msg = "完成job" + q.now_process.num.ToString() + "\r\n";
                    q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                    p.wait[p.length++] = q.now_process;
                    q.now_process = q.del_highest_response_ratio();

                    return msg;

                }
                else return null;
            }
            else if (q.now_process != null && q.now_process.period_need_left <= 0)
            {
                msg = "完成job" + q.now_process.num + "\r\n";
                q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                p.wait[p.length++] = q.now_process;
                q.now_process = null;
                return msg;
            }
            else return null;
        }
        public static string 优先级调度算法(queue q, queuefinish p)
        {
            string msg;
            process p1;
            if (q.length > 0)
            {
                if (q.now_process == null)
                {
                    q.now_process = q.del_highest_priority();

                }
                if (q.now_process.period_need_left <= 0)
                {
                    msg = "完成job" + q.now_process.num.ToString() + "\r\n";
                    q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                    p.wait[p.length++] = q.now_process;
                    q.now_process = q.del_highest_priority();

                    return msg;

                }
                else if (q.now_process.prior > (p1 = (q.length > 0 ? q.del_highest_priority() : q.now_process)).prior)
                {
                    q.add(q.now_process);
                    q.now_process = p1;
                    return null;
                }

                else
                {

                    if (q.now_process != p1) q.add(p1);
                    return null;
                }
            }
            else if (q.now_process != null && q.now_process.period_need_left <= 0)
            {
                msg = "完成job" + q.now_process.num + "\r\n";
                q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                p.wait[p.length++] = q.now_process;
                q.now_process = null;
                return msg;
            }
            else return null;
        }
        public static string RR(queue q,queuefinish p)
        {
            string msg;
            process p1;

            if (q.length > 0)
            {
                if (q.now_process == null)
                {
                    q.now_process = q.del_first();

                }
                if (q.now_process.period_need_left <= 0)
                {
                    msg = "完成job" + q.now_process.num.ToString() + "\r\n";
                    q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                    p.wait[p.length++] = q.now_process;
                    q.now_process = q.del_first();

                    return msg;

                }
                else if (Form1.time_interval==0&&Form1 .change_enable==true)
                {
                    q.add(q.now_process);
                    p1=q.del_first();
                    q.now_process = p1;
                    Form1.change_enable =false ;
                    return null;
                }

                else
                {
                    return null;
                }
            }
            else if (q.now_process != null && q.now_process.period_need_left <= 0)
            {
                msg = "完成job" + q.now_process.num + "\r\n";
                q.now_process.time_out = q.now_process.wait_already + q.now_process._need_period_num + q.now_process._time_in;
                p.wait[p.length++] = q.now_process;
                q.now_process = null;
                return msg;
            }
            else return null;
        }