日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

非抢占式优先算法例题_非抢占短作业优先算法源代码(C语言)

發布時間:2023/12/4 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 非抢占式优先算法例题_非抢占短作业优先算法源代码(C语言) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

#include

#include

#define MAX 5 //進程數

/*短作業優先算法*/

struct pro

{

int num; //進程名

int arriveTime; //到達時間

int burst; //運行時間;

struct pro *next;

};

//函數聲明

struct pro* creatList();

void insert(struct pro *head,struct pro *s);

struct pro* searchByAT(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

{

s=(struct pro*)malloc(sizeof(struct pro));

printf("請輸入進程名:\n");

scanf("%d",&(s->num));

printf("請輸入到達時間:\n");

scanf("%d",&(s->arriveTime));

printf("請輸入運行時間:\n");

scanf("%d",&(s->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,*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 count=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->burst;

flag=p; //flag記錄返回指針

while(count>0)

{

if(q->burst

{

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) //如果當前就緒隊列中沒有進程,時間自增

time++;

else if(count==1) //如果就緒隊列中只有1個進程,則必定是第一個節點

{

t=head;

s=t->next;

printf("進程名:%d\n",s->num);

printf("到達時間:%d\n",s->arriveTime);

printf("運行開始時間:%d\n",time);

printf("響應時間:%d\n",time-s->arriveTime);

time+=s->burst;

printf("

總結

以上是生活随笔為你收集整理的非抢占式优先算法例题_非抢占短作业优先算法源代码(C语言)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。