




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、精選優質文檔-傾情為你奉上非搶占短作業優先算法源代碼(C語言) #include <stdio.h>#include <stdlib.h>#define MAX 5 /進程數/*短作業優先算法*/struct proint num; /進程名int arriveTime; /到達時間int burst; /運行時間;struct pro *next;/函數聲明struct pro* creatList();void insert(struct pro *head,struct pro *s); struct pro* searchByAT
2、(struct pro *head,int AT); void run(struct pro *head);void del(struct pro* p);int getCount(struct pro *head,int time);struct pro* creatList() /創建鏈表,按照進程的到達時間排列struct pro* head=(struct pro*)malloc(sizeof(struct pro);head->next=NULL;struct pro* s;int i;for(i=0;i<MAX;i+)s=(struct pro*)mal
3、loc(sizeof(struct pro);printf("請輸入進程名:n");scanf("%d",&(s->num);printf("請輸入到達時間:n");scanf("%d",&(s->arriveTime);printf("請輸入運行時間:n");scanf("%d",&(s->
4、burst);s->next=NULL;insert(head,s);return head;void insert(struct pro *head,struct pro *s) /插入節點struct pro *p=searchByAT(head,s->arriveTime);s->next=p->next;p->next=s;return;struct pro* searchByAT(struct pro *head,int AT) /查找第一個到達時間大于等于AT的節點,返回其前一個指針struct pro *p,*
5、q;p=head;q=head->next;while(q!=NULL&&q->arriveTime<=AT)p=q;q=q->next;return p;void del(struct pro* p) /刪除p的下一個節點struct pro *tmp;tmp=p->next;p->next=tmp->next;free(tmp);return;int getCount(struct pro *head,int time) /察看當前就緒隊列中的進程數int co
6、unt=0;struct pro *p,*q;p=head;q=p->next;while(q!=NULL&&q->arriveTime<=time)count+;p=q;q=q->next;return count;struct pro* SJF(struct pro *head,int count) /在頭節點后的count個節點中選擇burst最小的,返回其前一個節點的指針int min;struct pro *p,*q,*flag;p=head;q=p->next;min=q-&
7、;gt;burst;flag=p; /flag記錄返回指針while(count>0)if(q->burst<min)min=q->burst;flag=p;count-;p=q;q=q->next;return flag;void run(struct pro *head) /按短作業優先算法調度進程,并輸出其運行情況int time=0,count;struct pro *s,*t;while(head->next!=NULL)count=getCount(head,time);if(count=0) /如
8、果當前就緒隊列中沒有進程,時間自增time+;else if(count=1) /如果就緒隊列中只有1個進程,則必定是第一個節點t=head;s=t->next;printf("進程名:%dn",s->num);printf("到達時間:%dn",s->arriveTime);printf("運行開始時間:%dn",time);printf("響應時間:%dn",time-s->arriveTim
9、e);time+=s->burst;printf("運行結束時間:%dn",time);printf("周轉時間:%dn",time-s->arriveTime);printf("*n");del(t );else /如果就緒隊列中的進程數>=2,則在head后的count個節點中進行短作業優先調度t=SJF(head,count);s=t->next;printf("進程名:%dn",s->num);printf("到達時間:%dn",s->arriveTime);printf("運行開始時間:%dn",time);printf("響應時間:%dn",time-s->arriveTime);time+=s->burst;printf("運行結束時間:%dn",time);printf("周轉時間:%dn",time-s-&g
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 工藝品切換妝容 在泛黃的紙頁中燦爛光亮
- 房地產項目的合同管理與談判技巧
- 環境災害應急物資采購重點基礎知識點歸納
- 中式快餐的時尚魅力
- 青春期心理健康教育
- 元旦的鄉愁淡藍故事賞析
- 建筑垃圾處理與土木工程綠色施工的結合
- 女兒墻防水收頭金屬壓條技術專題
- 保險公司晚宴熱場活動方案
- 保險公司茶話會策劃方案
- 中南運控課設-四輥可逆冷軋機的卷取機直流調速系統設計
- 風景園林專業中級職稱《法律法規及技術標準》考試題及答案
- DB11T 893-2021 地質災害危險性評估技術規范
- 呼吸系統測試題(含參考答案)
- 歐洲文明概論學習通超星期末考試答案章節答案2024年
- 民兵知識小常識
- 山西省大同市平城區2023-2024學年六年級下學期期末考試英語試卷
- 2023年高考真題-地理(河北卷) 含答案
- 大學本科教學指導委員會章程
- 熱力學全冊配套完整課件3
- 部編版二年級下冊語文期末復習(全冊知識點)
評論
0/150
提交評論