#include <stdio.h>#include<string.h>structjcb{intArrtime,reqtime; intStarttime,zztime,endtime; floatZzxs; Charname[Ten];}; JCB a[Ten];voidFCFS (intNUMBER,JCB a[Ten]); main () {intnumber,i;//For (i=0;i<number;i++)//a[i].endtime==0;printf"Please enter the number of your jobs:", number); scanf ("%d",&Number ); for(i=0; i<number;i++) {printf ("Name:"); scanf ("%s",&a[i].name); printf ("Arrtime:"); scanf ("%d",&a[i].arrtime); printf ("Reqtime:"); scanf ("%d",&a[i].reqtime); } printf ("\tname\tarrtime\treqtime\tstarttime\tendtime\tzztime\tzzxs\n"); for(i=0; i<number;i++) { //printf ("%s", a[0].name);printf"\t%s\t%d\t%d %d%d%d%f\n", A[i].name,a[i].arrtime,a[i].reqtime,a[i].starttime, A[I].ENDTIME,A[I].ZZTIME,A[I].ZZXS); } printf ("First come first service: \ n"); FCFS (Number,a); for(i=0; i<number;i++) { //printf ("%s", a[0].name);printf"\t%s\t%d\t%d %d%d%d%f\n", A[i].name,a[i].arrtime,a[i].reqtime,a[i].starttime, A[I].ENDTIME,A[I].ZZTIME,A[I].ZZXS); }}voidFCFS (intNUMBER,JCB a[Ten]){ intI,J,TEMP1,TEMP2; Chartemp[Ten]; for(i=0; i<number;i++) { for(j=i+1; j<number;j++) { if(a[j].arrtime<a[i].arrtime) {Temp1=A[j].arrtime; Temp2=A[j].reqtime; A[j].arrtime=A[i].arrtime; A[j].reqtime=A[i].reqtime; A[i].arrtime=Temp1; A[i].reqtime=Temp2; strcpy (Temp,a[j].name); strcpy (A[j].name,a[i].name); strcpy (a[i].name,temp); } for(i=0; i<number;i++) {A[i].endtime=a[i].reqtime+A[i].arrtime; A[i].zztime=a[i].endtime-A[i].arrtime; } } }}
Experiment two operation scheduling simulation experiment experience: The experiment two only completed the first to serve the algorithm, and the algorithm also has a great flaw. This algorithm mainly constructs a structure, then defines the general variables of the job, such as arrival time, service time, end time, turnaround time and so on. The idea of first-come-first service is to dispatch the job by comparing the arrival time to the first. There are still two tasks at the same time to reach the problem, but also need to constantly improve.
Experiment two job scheduling simulation program