本篇文章是c++实现时间片轮转法,在这个算法中,任务数是随机的,但是因为用到排序算法,所以限制了任务数的大小,同时因为只是一个实现,所以也对到达时间进行了限制,不至于无限长时间之后才有任务到达,如果要模拟实际,可以把取模的大小更改,然后预留了优先级的位置,但在本算法中没有考虑优先级,因为后期会对优先级+时间轮转法进行编写,本算法只实现基本轮转
/pcb.h///
#include <iostream>
#include <stdlib.h>
#include <time.h>
#include <string>
using namespace std;
#define N 10
struct pcb
{
string pcbname;
int cometime;
int runtime;
char rate;
bool fl;
pcb *address;
pcb *next;
};
struct pcblist
{
pcb* head;
pcb* running;
pcb* next;
pcb* ending;
pcb* comming;
pcb* rear;
};
int rands();
///
void createlist(pcblist *t,int num);
void setcomelist(pcblist *t, int num, int &mask);
void QuickSort(pcb *E, int s, int t);
void operation(pcblist *t, int num,int mask);
///
void show(pcblist *t);
#include "pcb.h"