📄 作业调度.txt
字号:
#include "stdio.h"
#include "stdlib.h"
#define getjcb(type)(type*)malloc(sizeof(type))
#define NULL 0
struct jcb{char name[10];
int htime;
int ntime;
char state;
struct jcb *link;
} *ready=NULL,*p;
typedef struct jcb JCB;
int input()
{int num,i,t=0;
void sort();
printf("\ninput process number");
scanf("%d",&num);
for(i=1;i<=num;i++)
{printf("\nThe num %d",i);
p=(JCB*)malloc(sizeof(JCB));
printf("\nthe name of process:");
scanf("%s",p->name);
printf("\nthe time need:");
scanf("%d",&p->ntime);
p->htime=t; p->state='w'; p->link=NULL;
sort();
t++;
}
return t;
}
void sort()
{JCB *flag;
if(ready==NULL)
ready=p;
else{flag=ready;
while(flag->link!=NULL)
flag=flag->link;
flag->link=p;
}
}
void show()
{JCB *pr;
printf("\n***Now the process running is :%s ",p->name);
printf("\nname\thtime\tntime\tstate\n");
printf("%s\t",p->name);
printf("%d\t",p->htime);
printf("%d\t",p->ntime);
printf("%c\t",p->state);
printf("\n\n***Now the ready queue");
for(pr=ready;pr!=NULL;pr=pr->link)
{
printf("\nname\thtime\tntime\tstate\n");
printf("%s\t",pr->name);
printf("%d\t",pr->htime);
printf("%d\t",pr->ntime);
printf("%c\t",pr->state);
}
}
void running()
{printf("\nprocess [%s] has finished\n",p->name);
free(p);
}
main()
{
char c;
int t=0; int tb,tc,ti,wi;
int tis=0,wis=0,i=0;
t=input();
while(ready!=NULL)
{c=getchar();
++i;
p=ready;
ready=p->link;
p->link=NULL;
p->state='r';
tb=t;
show();
printf("\npress any key to continue...");
c=getchar();
running();
tc=tb+p->ntime;//完成时间
ti=tc-p->htime;//周转时间
tis+=ti;
wi=ti/p->ntime;//平均带权周转
wis+=wi;
printf("\nprocess [%d] start: %d \n", i,t);
printf("\nprocess finish:%d\n",tc);
printf("\nprocess turnover:%d\n",ti);
printf("\nprocess aveturn: %d\n",wi);
t=t+p->ntime;
printf("\npress any key to continue...");
c=getchar();
}
printf("\n***The whole process has been finished");
printf("\nthe whole turnover:%d\n",tis/i);
printf("\nthe whole aveturn:%d\n",wis/i);
printf("\npress any key to continue...");
c=getchar();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -