fcfs算法 c语言

该代码示例展示了如何用C语言实现FCFS进程调度算法,包括创建进程队列、按到达时间排序、模拟进程运行以及计算周转时间和带权周转时间。程序首先读取用户输入的进程信息,然后按照到达时间对进程进行调度并输出运行状态和相关时间指标。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#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 = 
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一串平凡的代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值