设计一个按优先数调度算法实现处理器调度的程序.
1个回答

#include

#include //提供atoi()函数

#include //提供clrscr()函数

#define M 10 //字符串大小常量

#define N 3 //进程数常量

#define SLOT 2

typedef struct node{

char name[M];

int prio; //优先级

int round; //时间片长度

int cputime; //已经使用的cpu时间

int needtime;//需要多少cpu时间

int count; //计数器

char state; //进程的当前状态

struct node *next; //指向下一个进程

}PCB;

PCB *finish,*ready,*tail,*run;

void ShowHead(char *s1,char *s2);

int Menu_Select();

void Creat(int select);

void InsertPriority(PCB *q);

void InsertSlot(PCB *q);

void PrintOneProcess(int select,PCB *q);

void PrintAllProcess(int select);

void FirstIn();

void FIFODo(int select);

void PriorityDo(int select);

void SlotDo(int select);

void Quit();

main()

{

while(1)

{

clrscr();

switch(Menu_Select())

{

case 1:

Creat(1);

FIFODo(1);

printf("nntt按回车键返回菜单...");

getchar();

getchar();

break;

case 2:

Creat(2);

PriorityDo(2);

printf("nntt按回车键返回菜单...");

getchar();

getchar();

break;

case 3:

Creat(3);

SlotDo(3);

printf("nntt按回车键返回菜单...");

getchar();

getchar();

break;

case 0:

Quit();

break;

}

}

}

/*打印每个界面的开头显示*/

void ShowHead(char *s1,char *s2)

{

printf("t nn");

gotoxy(13,15);

getchar();

printf("nttDo you really want to quit(y/Y or n/N):");

scanf("%c",&ch);

if(ch=='y' || ch=='Y')

{

printf("ntt按任意键退出系统...");

getchar();

exit(0);

}

}