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

#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静态变量的合理使用,以及当需要删除数组里面的元素(程序用了覆盖输出的方法)。

转载于:https://www.cnblogs.com/52728240qq-com/p/4952580.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值