欧美一区2区三区4区公司二百,国产精品婷婷午夜在线观看,自拍偷拍亚洲精品,国产美女诱惑一区二区

c語言之SJF

#include <malloc.h>
#include <stdio.h>
?
typedef struct table
{
? ? char name[10];//進程名
? ? int id;//進程id
? ? int atime;//到達時間
? ? int stime;//開始時間
? ? int runtime;//運行時間
? ? int ftime;//完成時間
? ? float total;//周轉時間
? ? float weight;//帶權周轉時間
? ? int starttime;
? ? int finishtime;
}PCB;
?
typedef struct _Node
{
? ? struct _Node* next;
? ? PCB pcb;
}node;
?
struct node* creat(int count)
{
? ? node* head = malloc(sizeof(node));
? ? head->next = NULL;
? ? node* move = head;
?
? ? for (int i = 0; i < count; i++)
? ? {
? ? ? ? node* fresh = malloc(sizeof(node));
? ? ? ? fresh->next = NULL;
? ? ? ? move->next = fresh;
?
? ? ? ? printf("請輸入第%d個進程的id、到達時間、運行時間:\n", i + 1);
? ? ? ? scanf("%d%s%d%d", &fresh->pcb.id, fresh->pcb.name, &fresh->pcb.atime, &fresh->pcb.runtime);
?
? ? ? ? move = fresh;
? ? }
? ? return head;
}
?
void fcfs(node* head) {
? ? for (node* turn = head->next; turn->next != NULL; turn = turn->next)
? ? {
? ? ? ? for (node* move = head->next; move->next != NULL; move = move->next)
? ? ? ? {
? ? ? ? ? ? if (move->pcb.atime > move->next->pcb.atime)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? PCB temp = move->pcb;
? ? ? ? ? ? ? ? move->pcb = move->next->pcb;
? ? ? ? ? ? ? ? move->next->pcb = temp;
? ? ? ? ? ? }
?
? ? ? ? }
?
? ? }
}
?
void middle(node* head) {
? ? for (node* turn = head->next; turn->next != NULL; turn = turn->next)
? ? {
? ? ? ? for (node* move = head->next; move->next != NULL; move = move->next)
? ? ? ? {
? ? ? ? ? ? if (move->pcb.atime == move->next->pcb.atime && move->pcb.runtime > move->next->pcb.runtime) {
? ? ? ? ? ? ? ? PCB temp = move->pcb;
? ? ? ? ? ? ? ? move->pcb = move->next->pcb;
? ? ? ? ? ? ? ? move->next->pcb = temp;
? ? ? ? ? ? }
?
? ? ? ? }
? ? }
}
?
void sjf(node* head) {
? ? node* temp = head->next;
? ? node* move = head->next->next;
? ? temp->pcb.starttime = temp->pcb.atime;
? ? temp->pcb.finishtime = temp->pcb.starttime + temp->pcb.runtime;
? ? int num = temp->pcb.finishtime;
? ? while (move->next != NULL) {
? ? ? ? temp = temp->next;
? ? ? ? move = move->next;
? ? ? ? node* tap = move;
? ? ? ? while (move != NULL) {
? ? ? ? ? ? if (temp->pcb.atime <= num && move->pcb.atime <= num && temp->pcb.runtime > move->pcb.runtime) {
? ? ? ? ? ? ? ? PCB map = temp->pcb;
? ? ? ? ? ? ? ? temp->pcb = move->pcb;
? ? ? ? ? ? ? ? move->pcb = map;
? ? ? ? ? ? ? ? move = move->next;
? ? ? ? ? ? }
? ? ? ? ? ? else {
? ? ? ? ? ? ? ? break;
? ? ? ? ? ? }
? ? ? ? }
? ? ? ? if (temp->pcb.atime < num) {
? ? ? ? ? ? num = num + temp->pcb.runtime;
?
? ? ? ? }
? ? ? ? else {
? ? ? ? ? ? num = temp->pcb.atime + temp->pcb.runtime;
?
? ? ? ? }
? ? ? ? move = tap;
? ? }
}
?
?
void running(node* head) {
? ? node* move = head->next;
? ? while (move != NULL) {
? ? ? ? printf("%s程序正在運行.....\n", move->pcb.name);
? ? ? ? move = move->next;
? ? }
}
?
void s_f_t_w_time(node* head) {
? ? node* move = head->next->next;
? ? node* first = head->next;
? ? first->pcb.total = first->pcb.runtime;
? ? first->pcb.stime = first->pcb.atime;
? ? first->pcb.ftime = first->pcb.stime + first->pcb.runtime;
? ? first->pcb.weight = first->pcb.total / first->pcb.runtime;
? ? printf("%d %4s %7d %11d %10d %10d %16f %10f\n", first->pcb.id, first->pcb.name, first->pcb.atime, first->pcb.runtime, first->pcb.stime, first->pcb.ftime, first->pcb.total, first->pcb.weight);
? ? while (move != NULL) {
? ? ? ? if (first->next->pcb.atime <= first->pcb.ftime) {
? ? ? ? ? ? first->next->pcb.stime = first->pcb.ftime;
? ? ? ? ? ? first->next->pcb.ftime = first->next->pcb.stime + first->next->pcb.runtime;
? ? ? ? ? ? first->next->pcb.total = first->next->pcb.stime + first->next->pcb.runtime - first->next->pcb.atime;
? ? ? ? ? ? first->next->pcb.weight = first->next->pcb.total / first->next->pcb.runtime;
? ? ? ? }
? ? ? ? else {
? ? ? ? ? ? first->next->pcb.stime = first->next->pcb.atime;
? ? ? ? ? ? first->next->pcb.ftime = first->next->pcb.stime + first->next->pcb.runtime;
? ? ? ? ? ? first->next->pcb.total = first->next->pcb.stime + first->next->pcb.runtime - first->next->pcb.atime;
? ? ? ? ? ? first->next->pcb.weight = first->next->pcb.total / first->next->pcb.runtime;
? ? ? ? }
? ? ? ? printf("%d %4s %7d %11d %10d %10d %16f %10f\n", first->next->pcb.id, first->next->pcb.name, first->next->pcb.atime, first->next->pcb.runtime, first->next->pcb.stime, first->next->pcb.ftime, first->next->pcb.total, first->next->pcb.weight);
? ? ? ? first = first->next;
? ? ? ? move = move->next;
? ? }
}
?
int main(void) {
? ? node* p;
? ? printf("請輸入進程數量:\n");
? ? int count;
? ? scanf("%d", &count);
? ? p = creat(count);
? ? fcfs(p);
? ? middle(p);
? ? sjf(p);
? ? running(p);
? ? printf(" id ? ?進程名 ? 到達時間 ? 運行時間 ? 開始時間 ? 結束時間 ? 周轉時間 ? 帶權周轉時間\n");
? ? s_f_t_w_time(p);
?
}

c語言之SJF

文章鏈接: http://www.qzkangyuan.com/27156.html

文章標題:c語言之SJF

文章版權:夢飛科技所發布的內容,部分為原創文章,轉載請注明來源,網絡轉載文章如有侵權請聯系我們!

聲明:本站所有文章,如無特殊說明或標注,均為本站原創發布。任何個人或組織,在未征得本站同意時,禁止復制、盜用、采集、發布本站內容到任何網站、書籍等各類媒體平臺。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。

給TA打賞
共{{data.count}}人
人已打賞
建站教程投稿分享

c語言之fcfs

2024-1-29 13:08:26

投稿分享

SQLServer2000同步復制技術實現操作步驟

2024-1-30 17:11:21

0 條回復 A文章作者 M管理員
    暫無討論,說說你的看法吧
?
個人中心
購物車
優惠劵
今日簽到
有新私信 私信列表
搜索

夢飛科技 - 最新云主機促銷服務器租用優惠

主站蜘蛛池模板: 砀山县| 志丹县| 江永县| 贵阳市| 普兰县| 东乡族自治县| 华蓥市| 科技| 克拉玛依市| 肃南| 得荣县| 葫芦岛市| 吉木乃县| 永平县| 綦江县| 阳高县| 合山市| 五原县| 定陶县| 苗栗县| 淮南市| 万源市| 尖扎县| 舒城县| 桂东县| 自治县| 兴国县| 南华县| 会东县| 普定县| 岐山县| 广南县| 龙川县| 连州市| 临海市| 彰化县| 华蓥市| 虹口区| 佛坪县| 厦门市| 西安市|