亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? scheduler.cpp

?? 當時上操作系統課后
?? CPP
字號:
#include <string>
#include <stdlib.h>
#include <time.h>
#include <iostream>
#include <conio.h>
#define TIMES 40
using namespace std;

class PCB{
	public:
		int id;
		int status;
		int needtime;
		int exectime;
		int waittime;
		int pri;
		PCB * next;

		PCB(int id,int time,int pri){
			this->id=id;
			status=0;
			needtime=time;
			exectime=0;
			waittime=0;
			this->pri=pri;
			next=NULL;
		}
};

PCB * head;
PCB * last;
PCB * exec;

PCB * NewPCB[TIMES];

int Random(int low,int high){
	return(low+rand()%(high-low+1));
}

void RandomEvent(){
	int id=1;
	for (int i=0;i<TIMES;i++){
		if (Random(0,10)>=8){
			NewPCB[i]=new PCB(id++,Random(1,5),Random(0,5));
		}else{
			NewPCB[i]=NULL;
		}
	}
}


void FCFS(){
	head=NULL;
	last=NULL;
	exec=NULL;
	PCB * pcb;
	cout<<"先來先服務調度算法:\n";
	for (int time=0;time<TIMES;time++){
		pcb=head;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		if (exec){
			exec->exectime++;
			if (exec->exectime>=exec->needtime){
				cout<<exec->id<<"結束,周轉時間:"<<exec->exectime+exec->waittime<<",帶權周轉時間:"<<(exec->exectime+exec->waittime)/exec->needtime<<endl;
				exec=NULL;
			}
		}
		if (NewPCB[time]){
			if (!head){
				head=new PCB(*NewPCB[time]);
				last=head;
			}else{
				last->next=new PCB(*NewPCB[time]);
				last=last->next;
			}
			cout<<last->id<<"創建,需要時間:"<<last->needtime<<",優先級:"<<last->pri<<endl;
		}
		if (!exec){
			if (head){
				exec=head;
				head=head->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
			}
		}
	}
}

void SPF(){
	head=NULL;
	last=NULL;
	exec=NULL;
	PCB * pcb;
	cout<<"\n短進程優先調度算法:\n";
	for (int time=0;time<TIMES;time++){
		pcb=head;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		if (exec){
			exec->exectime++;
			if (exec->exectime>=exec->needtime){
				cout<<exec->id<<"結束,周轉時間:"<<exec->exectime+exec->waittime<<",帶權周轉時間:"<<(exec->exectime+exec->waittime)/exec->needtime<<endl;
				exec=NULL;
			}
		}
		if (NewPCB[time]){
			if (!head){
				head=new PCB(*NewPCB[time]);
				last=head;
			}else{
				last=NULL;
				pcb=head;
				while(pcb){
					if(NewPCB[time]->needtime<pcb->needtime){
						pcb=new PCB(*NewPCB[time]);
						if(!last){
							pcb->next=head;
							head=pcb;
						}else{
							pcb->next=last->next;
							last->next=pcb;
						}
						last=pcb;
						break;
					}
					last=pcb;
					pcb=pcb->next;
				}
				if (!pcb){
					last->next=new PCB(*NewPCB[time]);
					last=last->next;
				}
			}
			cout<<last->id<<"創建,需要時間:"<<last->needtime<<",優先級:"<<last->pri<<endl;
		}
		if (!exec){
			if (head){
				exec=head;
				head=head->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
			}
		}
	}
}

void FPF(){
	head=NULL;
	last=NULL;
	exec=NULL;
	PCB * pcb;
	cout<<"\n高優先權優先調度算法:\n";
	for (int time=0;time<TIMES;time++){
		pcb=head;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		if (exec){
			exec->exectime++;			
			if (exec->exectime>=exec->needtime){
				cout<<exec->id<<"結束,周轉時間:"<<exec->exectime+exec->waittime<<",帶權周轉時間:"<<(exec->exectime+exec->waittime)/exec->needtime<<endl;
				exec=NULL;
			}
		}
		if (NewPCB[time]){
			if (!head){
				head=new PCB(*NewPCB[time]);
				last=head;
			}else{
				last=NULL;
				pcb=head;
				while(pcb){
					if(NewPCB[time]->pri>pcb->pri){
						pcb=new PCB(*NewPCB[time]);
						if(!last){
							pcb->next=head;
							head=pcb;
						}else{
							pcb->next=last->next;
							last->next=pcb;
						}
						last=pcb;
						break;
					}
					last=pcb;
					pcb=pcb->next;
				}
				if (!pcb){
					last->next=new PCB(*NewPCB[time]);
					last=last->next;
				}
			}
			cout<<last->id<<"創建,需要時間:"<<last->needtime<<",優先級:"<<last->pri<<endl;
		}
		if (!exec){
			if (head){
				exec=head;
				head=head->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
			}
		}
	}
}

void SortByResponseRate(){
	if (!head){
		return;
	}
	PCB * last;
	PCB * pcb;
	PCB * prevh;
	PCB * highest;
	
	last=head;
	highest=head;
	pcb=head->next;
	while(pcb){
		if (pcb->waittime/pcb->needtime>highest->waittime/highest->needtime){
			prevh=last;
			highest=pcb;
		}
		last=pcb;
		pcb=pcb->next;
	}
	if (highest==head){
		return;
	}else{
		prevh->next=highest->next;
		highest->next=head;
		head=highest;
	}

}

void HRF(){
	head=NULL;
	last=NULL;
	exec=NULL;
	PCB * pcb;
	cout<<"\n高響應比優先調度算法:\n";
	for (int time=0;time<TIMES;time++){
		pcb=head;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		if (exec){
			exec->exectime++;
			if (exec->exectime>=exec->needtime){
				cout<<exec->id<<"結束,周轉時間:"<<exec->exectime+exec->waittime<<",帶權周轉時間:"<<(exec->exectime+exec->waittime)/exec->needtime<<endl;
				exec=NULL;
			}
		}
		if (NewPCB[time]){
			if (!head){
				head=new PCB(*NewPCB[time]);
				last=head;
			}else{
				last->next=new PCB(*NewPCB[time]);
				last=last->next;
			}
			cout<<last->id<<"創建,需要時間:"<<last->needtime<<",優先級:"<<last->pri<<endl;
		}
		if (!exec){
			SortByResponseRate();
			if (head){
				exec=head;
				head=head->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
			}
		}
	}
}

void TSC(){
	head=NULL;
	last=NULL;
	exec=NULL;
	PCB * pcb;
	cout<<"\n時間輪轉調度算法:\n";
	for (int time=0;time<TIMES;time++){
		pcb=head;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		if (exec){
			exec->exectime++;
			if (exec->exectime>=exec->needtime){
				cout<<exec->id<<"結束,周轉時間:"<<exec->exectime+exec->waittime<<",帶權周轉時間:"<<(exec->exectime+exec->waittime)/exec->needtime<<endl;
				exec=NULL;
			}
		}
		if (NewPCB[time]){
			if (!head){
				head=new PCB(*NewPCB[time]);
				last=head;
			}else{
				last->next=new PCB(*NewPCB[time]);
				last=last->next;
			}
			cout<<last->id<<"創建,需要時間:"<<last->needtime<<",優先級:"<<last->pri<<endl;
		}
		if (!exec){
			if (head){
				exec=head;
				head=head->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
			}
		}else{
			if (head){
				last->next=exec;
				last=last->next;
				exec=head;
				head=head->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
			}
		}
	}
}

void MFQ(){
	PCB * q1=NULL;
	PCB * q2=NULL;
	PCB * q3=NULL;
	PCB * q4=NULL;
	PCB * pcb;
	int nextq;
	PCB * q1last=NULL;
	exec=NULL;
	cout<<"\n多級反饋隊列調度算法:\n";
	for (int time=0;time<TIMES;time++){
		pcb=q1;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		pcb=q2;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		pcb=q3;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		pcb=q4;
		while(pcb){
			pcb->waittime++;
			pcb=pcb->next;
		}
		if (exec){
			exec->exectime++;
			if (exec->exectime>=exec->needtime){
				cout<<exec->id<<"結束,周轉時間:"<<exec->exectime+exec->waittime<<",帶權周轉時間:"<<(exec->exectime+exec->waittime)/exec->needtime<<endl;
				exec=NULL;
			}else{
				switch(nextq){
					case 2:
						if (!q2){
							q2=exec;
							pcb=NULL;
						}else{
							pcb=q2;
						}
						break;
					case 3:
						if (!q3){
							q3=exec;
							pcb=NULL;
						}else{
							pcb=q3;
						}
						break;
					case 4:
						if (!q4){
							q4=exec;
							pcb=NULL;
						}else{
							pcb=q4;
						}
						break;
					default:
						//ERROR
						break;
				}
				if (pcb){
					while(pcb->next){
						pcb=pcb->next;
					}
					pcb->next=exec;
				}
				exec=NULL;
			}
		}
		if (NewPCB[time]){
			if (!q1){
				q1=new PCB(*NewPCB[time]);
				q1last=q1;
			}else{
				q1last->next=new PCB(*NewPCB[time]);
				q1last=q1last->next;
			}
			cout<<q1last->id<<"創建,需要時間:"<<q1last->needtime<<",優先級:"<<q1last->pri<<endl;
		}
		if (!exec){
			if (q1){
				exec=q1;
				q1=q1->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
				nextq=2;
				continue;
			}
			if (q2){
				exec=q2;
				q2=q2->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
				nextq=3;
				continue;
			}
			if (q3){
				exec=q3;
				q3=q3->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
				nextq=4;
				continue;
			}
			if (q4){
				exec=q4;
				q4=q4->next;
				exec->next=NULL;
				cout<<exec->id<<"開始執行。"<<endl;
				nextq=4;
				continue;
			}
		}
	}
}

void main(){
	srand(time(0));
	RandomEvent();
	int j=0;
	FCFS();
	SPF();
	FPF();
	HRF();
	TSC();
	MFQ();
	getch();
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲电影第三页| 欧美极品xxx| 麻豆中文一区二区| 日韩欧美综合一区| 国产精品1区2区3区| 国产精品热久久久久夜色精品三区| 国产精品一区二区免费不卡 | 国产成人无遮挡在线视频| 精品裸体舞一区二区三区| 韩国视频一区二区| 中文字幕在线不卡视频| 色婷婷综合久久久久中文一区二区| 亚洲综合视频在线| 日韩欧美国产麻豆| 99r国产精品| 天堂成人免费av电影一区| 精品国产乱码久久久久久久| 成人精品一区二区三区中文字幕| 亚洲综合男人的天堂| 日韩一级完整毛片| av午夜精品一区二区三区| 婷婷国产v国产偷v亚洲高清| 久久综合狠狠综合久久综合88| 91麻豆免费观看| 免费黄网站欧美| ㊣最新国产の精品bt伙计久久| 欧美精品色综合| 成人午夜精品一区二区三区| 午夜成人免费视频| 国产肉丝袜一区二区| 欧美日韩久久久一区| 国产乱人伦偷精品视频免下载| 亚洲精品视频在线看| 久久九九久久九九| 欧美疯狂做受xxxx富婆| 成人av资源站| 国产美女精品人人做人人爽| 五月天视频一区| 国产精品国产三级国产aⅴ中文| 日韩午夜中文字幕| 欧美性欧美巨大黑白大战| 粉嫩av一区二区三区| 日本欧美加勒比视频| 亚洲人成影院在线观看| 久久精品夜色噜噜亚洲aⅴ| 欧美日韩成人一区二区| 成熟亚洲日本毛茸茸凸凹| 麻豆精品一区二区av白丝在线| 亚洲欧美日韩中文播放| 国产精品色一区二区三区| 精品国产精品一区二区夜夜嗨| 欧美亚洲国产一区二区三区va| 不卡视频在线观看| 国产精品夜夜嗨| 青青青伊人色综合久久| 亚洲国产日日夜夜| 亚洲人成伊人成综合网小说| 欧美激情综合网| 国产欧美日韩久久| 国产欧美日韩不卡| 久久久久亚洲综合| 精品国产一二三| 欧美一区二区三区免费视频| 欧美伦理电影网| 欧美日韩视频不卡| 欧美日韩色综合| 欧美日韩一区高清| 欧美无砖专区一中文字| 91久久一区二区| 欧美在线观看视频在线| 欧美性色黄大片手机版| 欧美色图天堂网| 欧美日韩1234| 欧美精品tushy高清| 欧美精三区欧美精三区| 欧美久久久久中文字幕| 8x8x8国产精品| 欧美成人精品福利| wwww国产精品欧美| 国产情人综合久久777777| 国产精品国产三级国产a| 中文字幕亚洲综合久久菠萝蜜| 中文字幕一区二区视频| 亚洲美女淫视频| 亚洲图片自拍偷拍| 日本aⅴ精品一区二区三区| 麻豆freexxxx性91精品| 国产一区二区视频在线播放| 国产美女在线精品| jizz一区二区| 在线看不卡av| 91精品中文字幕一区二区三区| 91精品久久久久久久91蜜桃| 日韩一级免费观看| 久久久久久日产精品| 国产精品久久久久久久岛一牛影视| 亚洲日本青草视频在线怡红院 | 精品一区二区三区影院在线午夜 | 日韩在线一二三区| 人人狠狠综合久久亚洲| 国产麻豆9l精品三级站| 91麻豆国产自产在线观看| 精品视频一区二区三区免费| 精品国一区二区三区| 国产欧美一二三区| 亚洲成va人在线观看| 国产真实乱子伦精品视频| 91网上在线视频| 日韩一级黄色大片| 中文字幕在线不卡| 青娱乐精品在线视频| youjizz久久| 欧美一区在线视频| 国产精品久久久久影院| 日日夜夜精品视频免费| 粉嫩aⅴ一区二区三区四区| 欧美性感一区二区三区| 久久蜜桃av一区精品变态类天堂| 亚洲激情图片小说视频| 麻豆精品一区二区av白丝在线| 99久久精品免费精品国产| 欧美精品日韩综合在线| 中文字幕在线不卡视频| 久久av资源网| 91久久精品日日躁夜夜躁欧美| 26uuu欧美| 午夜伊人狠狠久久| av电影在线不卡| 精品久久久久一区| 亚洲18女电影在线观看| 成人免费看片app下载| 日韩一卡二卡三卡| 亚洲高清三级视频| 99riav久久精品riav| 国产亚洲一区二区三区在线观看| 午夜视频在线观看一区| 91尤物视频在线观看| 久久久亚洲综合| 久久精品国产一区二区三| 在线观看亚洲a| 国产丝袜美腿一区二区三区| 日本怡春院一区二区| 在线观看国产91| 亚洲日本丝袜连裤袜办公室| 国产成人在线网站| 久久久精品欧美丰满| 久久精品免费观看| 欧美日韩成人在线| 亚洲成人精品一区| 欧美中文字幕一区| 一区二区三区四区在线免费观看 | 五月天精品一区二区三区| 99国产精品久久久久久久久久| 26uuu亚洲综合色欧美| 青青草原综合久久大伊人精品优势| 色吧成人激情小说| 一区二区三区四区在线| 91免费看`日韩一区二区| 国产精品久久福利| 99这里只有久久精品视频| 国产精品久久久一区麻豆最新章节| 国产高清精品久久久久| 久久蜜桃av一区精品变态类天堂| 久久97超碰色| 久久婷婷一区二区三区| 国产在线看一区| 久久久久久久电影| 国产不卡免费视频| 中文字幕av一区二区三区高| 国产精品69久久久久水密桃| 国产精品私人影院| 99久久综合色| 亚洲国产成人porn| 91精品欧美一区二区三区综合在 | 精品美女在线观看| 国产精品一二三区| 国产精品久99| 欧美日产国产精品| 激情综合色综合久久综合| 久久这里只精品最新地址| 国产精品2024| 中文字幕综合网| 欧美三级中文字幕| 蜜臀a∨国产成人精品| 亚洲精品一区二区三区在线观看| 国产激情视频一区二区在线观看| 国产精品午夜春色av| 欧美亚洲国产一区二区三区| 免费在线观看成人| 国产欧美日韩三级| 在线观看成人小视频| 精品综合免费视频观看| 亚洲国产精品精华液2区45| 在线亚洲一区二区| 蜜臀久久99精品久久久久宅男| 久久久久久综合| 欧美性大战xxxxx久久久| 极品少妇xxxx精品少妇| 中文一区二区完整视频在线观看 | 国内外成人在线视频|