c语言之fcfs

#include <malloc.h>
#include <stdio.h>
?
typedef struct?
{
? ? char name[10];//进程名
? ? int id;//进程id
? ? int atime;//到达时间
? ? int stime;//开始时间
? ? int runtime;//运行时间
? ? int ftime;//完成时间
? ? float total;//周转时间
? ? float weight;//带权周转时间
}PCB;
?
typedef struct _Node
{
? ? struct _Node* next;
? ? PCB pcb;
}node;
?
struct node* creat()
{
? ? node* head = malloc(sizeof(node));
? ? head->next = NULL;
? ? node* move = head;
?
? ? printf("请输入进程数量:\n");
? ? int count;
? ? scanf("%d", &count);
? ? 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 running(node* head) {
? ? node* move = head->next;//创建move指针控制循环次数
? ? 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;//创建move指针控制循环次数
? ? node* first = head->next;//将首结点的地址数据传入first指针中
? ? 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;
? ? p = creat();
? ? fcfs(p);
? ? printf("\n");
? ? running(p);
? ? printf("\n");
? ? printf(" id ? ?进程名 ? 到达时间 ? 运行时间 ? 开始时间 ? 结束时间 ? 周转时间 ? 带权周转时间\n");
? ? s_f_t_w_time(p);
? ? return 0;
}

c语言之fcfs

?

文章链接: /27155.html

文章标题:c语言之fcfs

文章版权:云服务器租用科技所发布的内容,部分为原创文章,转载请注明来源,网络转载文章如有侵权请联系我们!

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
建站教程

数据结构之栈(四)

2023-12-22 10:09:01

建站教程投稿分享

c语言之SJF

2024-1-29 13:16:21

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧

云服务器租用科技 - 最新云主机促销服务器租用优惠

http://www.vxiaotou.com