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

📄 zuoyediaodu.cpp

📁 操作系统课程设计之作业调度算法
💻 CPP
字号:
#include"stdlib.h"
#include"string.h"
#include"iostream.h"
typedef struct JCB
{
	char name[4];
    int length;
	int printer;
	int tape;
	int runtime;
	int waittime;
	struct JCB *next;
}jcb;
jcb *head; int tape,printer; long memory; 
void run()
{
	float max,k=0; jcb *p,*q,*s,*t;
	do
	{
		p=head;   q=s=NULL; k=0;
		while(p!=NULL)
		{
			if((p->length<=memory)&&(p->tape<=tape)&&(p->printer<=printer))
			{
				max=(float)(p->waittime)/p->runtime;
				if(q==NULL||max>k)
				{
					k=max;
					q=p;//当前响应比大的节点q
					t=s;//响应比大的节点的前一节点记录
				}
			}
			s=p;//记录下次执行节点的前一节点,为后面做准备
			p=p->next;
		}

		if(q!=NULL)//前面不执行Q=空,即设备不够用或者已经执行完
		{
			cout<<"**************************************************"<<endl;
			if(t==NULL)   head=head->next;//第一个为最大时指针后移
        	else   t->next=q->next;//将P节点从队列除去
        	memory=memory-q->length;
        	tape=tape-q->tape;
        	printer=printer-q->printer;
        	cout<<"选中的作业:"<<q->name;
            cout<<"     响应比:"<<k<<endl;
			cout<<"---大小:"<<q->length<<"  磁带:"<<q->tape<<"  打印机:"<<q->printer;
			cout<<"  等待时间:"<<q->waittime<<"  执行时间:"<<q->runtime<<endl;
		}
	}while(q!=NULL);
} 
void main()
{
	int le,tc,pc,wt,rt,N;
	char name[4];
	jcb *p;
	memory=65536;
	printer=2;
	tape=4;
	head=NULL;
	cout<<"输入作业数:N=";
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cout<<"输入作业名:";cin>>name;
		cout<<"作业大小:";cin>>le;
		cout<<"磁带机数:";cin>>tc;
		cout<<"打印机数:";cin>>pc;
		cout<<"等待时间:";cin>>wt;
		cout<<"执行时间:";cin>>rt;
		p=(jcb*)new(jcb);
		strcpy(p->name,name);
		p->length=le;
		p->printer=pc;
		p->tape=tc;
		p->runtime=rt;
		p->waittime=wt;
		p->next=head;//输入的放在链表前面
		head=p;
	}
	cout<<endl<<"系统内存:"<<memory<<"  打印机数:"<<printer<<"  磁带数:"<<tape<<endl;
	run();
} 

⌨️ 快捷键说明

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