FCFS的基本思想
先来先服务就是一个思想,谁先到先执行谁,也就是谁在任务队列等待时间越长越先被执行(相同度量下,就是在考虑谁先出队时就要重新更新一次所有任务的等待时间,统一度量)。
我的设计思路
首先,我知道了FCFS特性,这点和数据结构中经典的队列很有异曲同工之妙。后者就是一种先来先出的数据结构。于是我自然的想到了用队列来实现了,至于模拟嘛,我只需要模拟出那个“先来先服务”的意味就行了,你也可以千姿百态的设计哦!!!
图解
我的代码:
#include "stdio.h"
#include "string.h"
#include "stdio.h"
#include "stdlib.h"
#include "io.h"
#include "math.h"
#include "time.h"
#define MaxSize 100 /* 存储位置最多为100个*/
#define OK 1
#define True 1
#define False 0
#define OverFlow -1
#define UnderFlow -2
typedef struct
{
int number;//定义为任务代号
int time;//定义为等待时间
int kt;//定义为当