⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 form3.cs

📁 操作系统 作业调度程序 课程设计文档 对于linux系统的学习有很大帮助
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 操作系统
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }


        int total_wait = 0;

        private void button1_Click(object sender, EventArgs e)
        {

            int number = Convert.ToInt32(comboBox1.Text.ToString());

            if (number == 3)
            {
                PCB[] p1 = new PCB[number];
                int i1 = Convert.ToInt32(textBox2.Text.ToString());
                int j1 = Convert.ToInt32(textBox3.Text.ToString());
                int k1 = Convert.ToInt32(textBox4.Text.ToString());
                p1[0] = new PCB(i1, j1, k1);

                int i2 = Convert.ToInt32(textBox6.Text.ToString());
                int j2 = Convert.ToInt32(textBox7.Text.ToString());
                int k2 = Convert.ToInt32(textBox8.Text.ToString());
                p1[1] = new PCB(i2, j2, k2);

                int i3 = Convert.ToInt32(textBox9.Text.ToString());
                int j3 = Convert.ToInt32(textBox10.Text.ToString());
                int k3 = Convert.ToInt32(textBox11.Text.ToString());
                p1[2] = new PCB(i3, j3, k3);

                //先按先进来的时间排序
                for (int i = 0; i < number - 1; i++)
                {

                    for (int j = i + 1; j < number; j++)
                        if (p1[i].Intime > p1[j].Intime)
                        {
                            PCB Ptemp = new PCB();
                            Ptemp = p1[i];
                            p1[i] = p1[j];
                            p1[j] = Ptemp;
                        }
                }

                //把剩下的再按短时间来排序

                for (int i = 1; i < number; i++)
                {

                    for (int j = i + 1; j < number; j++)
                        if (p1[i].RequestTime > p1[j].RequestTime)
                        {
                            PCB Ptemp = new PCB();
                            Ptemp = p1[i];
                            p1[i] = p1[j];
                            p1[j] = Ptemp;
                        }
                }

                //如果有相同的时间和第一个相同并运行时间小就 交换
                for (int i = 0; i < number; i++)
                { 
                    for(int j = i+1 ; j<number; j++)
                    {
                        if((p1[0].Intime == p1[j].Intime) && p1[0].Intime >=p1[j].Intime)
                         {
                                PCB Ptemp = new PCB();//临时交换变量
                                Ptemp = p1[0];
                                p1[0] = p1[j];
                                p1[j] = Ptemp;
                          }   
                          
                    }
                    

                }
                //for (int i = 1; i < number; i++)
                //{

                //    for (int j = i + 1; j < number; j++)
                //    {

                //        if ((p1[0].Intime == p1[j].Intime) && p1[0].Intime >= p1[j].Intime)
                //        {
                //            PCB Ptemp = new PCB();//临时交换变量
                //            Ptemp = p1[i];
                //            p1[i] = p1[j];
                //            p1[j] = Ptemp;
                //        }

                       
                //    }
                //}

                p1[0].waittime = 0;
                for (int i = 0; i < number; i++)
                {

                    int n = p1[i].Intime / 100;

                    for (int j = i + 1; j < number; j++)
                    {

                        int m = p1[j].Intime / 100;
                        int k = m - n;
                        if (k > 0)
                            p1[j].waittime = Math.Abs((p1[i].Intime + p1[i].RequestTime) - p1[j].Intime + 40 * k);

                        else
                            p1[j].waittime = Math.Abs((p1[i].Intime + p1[i].RequestTime) - p1[j].Intime);

                        total_wait += p1[j].waittime;
                        break;

                    }



                }

                for (int i = 0; i < number; i++)
                {


                    textBox1.AppendText("序号" + '\t' + "进入系统的时间" + '\t' + "运行时间" + '\t' + "等待时间" + '\n' +
                                      p1[i].PID + '\t' + p1[i].Intime + '\t' + '\t' + p1[i].RequestTime + '\t' + '\t' + p1[i].waittime + '\n');
                }
                textBox1.AppendText("总等待时间为:" + total_wait);
            }
            if (number == 4)
            {
                PCB[] p1 = new PCB[number];
                int i1 = Convert.ToInt32(textBox2.Text.ToString());
                int j1 = Convert.ToInt32(textBox3.Text.ToString());
                int k1 = Convert.ToInt32(textBox4.Text.ToString());
                p1[0] = new PCB(i1, j1, k1);

                int i2 = Convert.ToInt32(textBox6.Text.ToString());
                int j2 = Convert.ToInt32(textBox7.Text.ToString());
                int k2 = Convert.ToInt32(textBox8.Text.ToString());
                p1[1] = new PCB(i2, j2, k2);

                int i3 = Convert.ToInt32(textBox9.Text.ToString());
                int j3 = Convert.ToInt32(textBox10.Text.ToString());
                int k3 = Convert.ToInt32(textBox11.Text.ToString());
                p1[2] = new PCB(i3, j3, k3);

                int i4 = Convert.ToInt32(textBox12.Text.ToString());
                int j4 = Convert.ToInt32(textBox13.Text.ToString());
                int k4 = Convert.ToInt32(textBox14.Text.ToString());
                p1[3] = new PCB(i4, j4, k4);



                //先按先进来的时间排序
                for (int i = 0; i < number - 1; i++)
                {

                    for (int j = i + 1; j < number; j++)
                        if (p1[i].Intime > p1[j].Intime)
                        {
                            PCB Ptemp = new PCB();
                            Ptemp = p1[i];
                            p1[i] = p1[j];
                            p1[j] = Ptemp;
                        }
                }
                //把剩下的再按短时间来排序

                for (int i = 1; i < number; i++)
                {

                    for (int j = i + 1; j < number; j++)
                        if (p1[i].RequestTime > p1[j].RequestTime)
                        {
                            PCB Ptemp = new PCB();
                            Ptemp = p1[i];
                            p1[i] = p1[j];
                            p1[j] = Ptemp;
                        }
                }

                //如果有相同的时间和第一个相同并运行时间小就 交换
                for (int i = 0; i < number; i++)
                {
                    for (int j = i + 1; j < number; j++)
                    {
                        if ((p1[0].Intime == p1[j].Intime) && p1[0].Intime >= p1[j].Intime)
                        {
                            PCB Ptemp = new PCB();//临时交换变量
                            Ptemp = p1[0];
                            p1[0] = p1[j];
                            p1[j] = Ptemp;
                        }

                    }


                }
                //for (int i = 1; i < number; i++)
                //{

                //    for (int j = i + 1; j < number; j++)
                //    {
                        
                //        if ((p1[i].Intime + p1[i].RequestTime) >= (p1[j].Intime + p1[j].RequestTime))
                        
                //        {
                //            PCB Ptemp = new PCB();//临时交换变量
                //            Ptemp = p1[i];
                //            p1[i] = p1[j];
                //            p1[j] = Ptemp;
                //        }

                //    }
                //}

                p1[0].waittime = 0;
                for (int i = 0; i < number; i++)
                {

                    int n = p1[i].Intime / 100;

                    for (int j = i + 1; j < number; j++)
                    {

                        int m = p1[j].Intime / 100;
                        int k = m - n;
                        if (k > 0)
                            p1[j].waittime = Math.Abs((p1[i].Intime + p1[i].RequestTime) - p1[j].Intime + 40 * k);

                        else
                            p1[j].waittime = Math.Abs((p1[i].Intime + p1[i].RequestTime) - p1[j].Intime);

                        total_wait += p1[j].waittime;
                        break;

                    }



                }

                for (int i = 0; i < number; i++)
                {


                    textBox1.AppendText("序号" + '\t' + "进入系统的时间" + '\t' + "运行时间" + '\t' + "等待时间" + '\n' +
                                      p1[i].PID + '\t' + p1[i].Intime + '\t' + '\t' + p1[i].RequestTime + '\t' + '\t' + p1[i].waittime + '\n');
                }
                textBox1.AppendText("总等待时间为:" + total_wait);
            }


            if (number == 5)
            {
                PCB[] p1 = new PCB[number];
                int i1 = Convert.ToInt32(textBox2.Text.ToString());
                int j1 = Convert.ToInt32(textBox3.Text.ToString());
                int k1 = Convert.ToInt32(textBox4.Text.ToString());
                p1[0] = new PCB(i1, j1, k1);

                int i2 = Convert.ToInt32(textBox6.Text.ToString());
                int j2 = Convert.ToInt32(textBox7.Text.ToString());
                int k2 = Convert.ToInt32(textBox8.Text.ToString());
                p1[1] = new PCB(i2, j2, k2);

                int i3 = Convert.ToInt32(textBox9.Text.ToString());
                int j3 = Convert.ToInt32(textBox10.Text.ToString());
                int k3 = Convert.ToInt32(textBox11.Text.ToString());
                p1[2] = new PCB(i3, j3, k3);

                int i4 = Convert.ToInt32(textBox12.Text.ToString());
                int j4 = Convert.ToInt32(textBox13.Text.ToString());
                int k4 = Convert.ToInt32(textBox14.Text.ToString());
                p1[3] = new PCB(i4, j4, k4);

                int i5 = Convert.ToInt32(textBox15.Text.ToString());
                int j5 = Convert.ToInt32(textBox16.Text.ToString());
                int k5 = Convert.ToInt32(textBox17.Text.ToString());
                p1[4] = new PCB(i5, j5, k5);

                //先按先进来的时间排序
                for (int i = 0; i < number - 1; i++)
                {

                    for (int j = i + 1; j < number; j++)
                        if ((p1[i].Intime > p1[j].Intime))
                        {
                            PCB Ptemp = new PCB();
                            Ptemp = p1[i];
                            p1[i] = p1[j];
                            p1[j] = Ptemp;
                           
                        }
                }
                //把剩下的再按短时间来排序

                for (int i = 1; i < number; i++)
                {

                    for (int j = i + 1; j < number; j++)
                        if ((p1[i].RequestTime > p1[j].RequestTime) )
                        {
                            PCB Ptemp = new PCB();
                            Ptemp = p1[i];
                            p1[i] = p1[j];
                            p1[j] = Ptemp;
                        }
                }

                //如果有相同的时间和第一个相同并运行时间小就 交换
                for (int i = 0; i < number; i++)
                {
                    for (int j = i + 1; j < number; j++)
                    {
                        if ((p1[0].Intime == p1[j].Intime) && p1[0].Intime >= p1[j].Intime)
                        {
                            PCB Ptemp = new PCB();//临时交换变量
                            Ptemp = p1[0];
                            p1[0] = p1[j];
                            p1[j] = Ptemp;
                        }

                    }


                }
                for (int i = 1; i < number; i++)
                {

                    for (int j = i + 1; j < number; j++)
                    {

                        if (Math.Abs(((p1[i].Intime + p1[i].RequestTime) - (p1[0].Intime + p1[0].RequestTime))) >= Math.Abs(((p1[j].Intime + p1[j].RequestTime) - (p1[0].Intime + p1[0].RequestTime))))
                        {
                            PCB Ptemp = new PCB();//临时交换变量
                            Ptemp = p1[i];
                            p1[i] = p1[j];
                            p1[j] = Ptemp;
                        }


                    }
                }

                p1[0].waittime = 0;
                for (int i = 0; i < number; i++)
                {

                    int n = p1[i].Intime / 100;

                    for (int j = i + 1; j < number; j++)
                    {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -