首页 > 编程语言 > 详细

操作系统 c++ 实现处理器调度

时间:2015-11-10 13:51:45      阅读:245      评论:0      收藏:0      [点我收藏+]
#include<iostream>
#include<string>
using namespace std;
struct pcb
{
    string name;
    int run_time;
    int level;
    int state = 0;
    struct pcb * next;
    
    
}k1,k2,k3,k4,k5;




int main()
{
    cout << "please input the level , run_time, name of process 1" << endl;
    cin >> k1.level >> k1.run_time>>k1.name;
    cout << "please input the level , run_time, name of process 2" << endl;
    cin >> k2.level >> k2.run_time>>k2.name;
    cout << "please input the level , run_time ,name of process 3" << endl;
    cin >> k3.level >> k3.run_time>>k3.name;
    cout << "please input the level , run_time ,name of process 4" << endl;
    cin >> k4.level >> k4.run_time>>k4.name;
    cout << "please input the level , run_time ,name of process 5" << endl;
    cin >> k5.level >> k5.run_time>>k5.name;

    pcb a[5] = { k1, k2, k3, k4, k5 };
    static int sxh = 5;



    while (sxh >= 1)
    {
        
        
        for (int i = 0; i < 4; i++)
        {
            for (int j = i + 1; j < 5; j++)
            {
                if (a[i].level <= a[j].level)
                {
                    pcb k;
                    k = a[i];
                    a[i] = a[j];
                    a[j] = k;


                }


            }
        }
        for (int i = 0; i <= sxh - 1; i++)
        {
            cout << " " << a[i].name;
        }
        cout << endl;
        cout << a[0].name<<" ";
        cout << endl;
        
        a[0].level--;
        a[0].run_time--;
        if (a[0].run_time == 0)
        {
            sxh--;
            a[0].level = 0;
            a[0].state = 1;

        }

    }
    system("pause");
    return 0;
    

    

    


}

这个程序重点是for循环的使用和static静态变量的合理使用,以及当需要删除数组里面的元素(程序用了覆盖输出的方法)。

操作系统 c++ 实现处理器调度

原文:http://www.cnblogs.com/52728240qq-com/p/4952580.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!