資源描述:
《C++動(dòng)態(tài)優(yōu)先級(jí)調(diào)度算法》由會(huì)員上傳分享,免費(fèi)在線(xiàn)閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫(kù)。
1、//stdafx.h:includefileforstandardsystemincludefiles,//orprojectspecificincludefilesthatareusedfrequently,but//arechangedinfrequently//#if!defined(AFX_STDAFX_H__66EA409C_5A68_4105_A5B2_DF00F9B5E262__INCLUDED_)#defineAFX_STDAFX_H__66EA409C_5A68_4105_A5B2_DF00F9B5E262__INCLUDED_#if_MSC_VER>1000#p
2、ragmaonce#endif//_MSC_VER>1000//TODO:referenceadditionalheadersyourprogramrequireshere//{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!defined(AFX_STDAFX_H__66EA409C_5A68_4105_A5B2_DF00F9B5E262__INCLUDED_)//動(dòng)態(tài)優(yōu)先級(jí).cpp:Defines
3、theentrypointfortheconsoleapplication.//#include"stdafx.h"#include#includetypedefstruct{//定義一個(gè)結(jié)構(gòu)體(進(jìn)程控制塊)charname[20];//進(jìn)程名intruntime;//運(yùn)行時(shí)間intprivilege;//到達(dá)時(shí)間charstate;//進(jìn)程狀態(tài),輸出為R時(shí)表示進(jìn)程處于就緒狀態(tài)}NODE;typedefstructnode{//定義一個(gè)結(jié)點(diǎn)NODEdata;//進(jìn)程數(shù)據(jù)structnode*next;//鏈接指針}LNODE;/*定義延
4、時(shí)函數(shù),模擬CPU調(diào)度用時(shí)過(guò)程*/voidDelay(inti){intx,y;while(i--){x=0;while(x<10000){y=0;while(y<40000)y++;x++;}}}/*按進(jìn)程優(yōu)先級(jí)排序*/voidInsertQueue(LNODE**head,NODEx){LNODE*p1,*p2,*p;p=newLNODE;//動(dòng)態(tài)分配新結(jié)點(diǎn)空間p->data=x;p->next=NULL;if(*head==NULL)//若為空鏈表*head=p;else//若為非空鏈表{p2=p1=*head;//在首結(jié)點(diǎn)之后尋找新結(jié)點(diǎn)p的插入位置while(p2!=NUL
5、L&&(p2->data).privilege<(p->data).privilege){p1=p2;p2=p2->next;}if(p2==NULL)//新結(jié)點(diǎn)插入尾結(jié)點(diǎn)后p1->next=p;elseif(p1==p2){p->next=*head;*head=p;}else//新結(jié)點(diǎn)插入p1和p2所指結(jié)點(diǎn)之間{p->next=p2;p1->next=p;}}}/*定義釋放隊(duì)列空間的函數(shù)*/voidDeleteQueue(LNODE**head,NODE*n){LNODE*p=*head;*n=(*head)->data;*head=(*head)->next;deletep;
6、cout<<"----------------------------------"<name<<'';}/*定義顯示進(jìn)程信息的函數(shù)*/voidOutput(LNODE**head){LNODE*p=*head;cout<<"進(jìn)程名剩余時(shí)間優(yōu)先級(jí)進(jìn)程狀態(tài)";do{cout<data).name<data).runtime<data).privilege<data).state<<'';p=p->next
7、;cout<