⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 partb.c~

📁 linked list linked list tree struc
💻 C~
字号:
/* * Wei Cui * wec924 * 981503 * * Brian Gale * bmg002 * 303473 */#include <stdio.h>#include <list.h>#include <unistd.h>#include <stdlib.h>typedef struct pcs {	int arrive;	float runtime;	int unread;	float startTime;}PCS;int main(int argc, char *argv[]) {	LIST *input, *readyQ;	float totalTime, timeSlice, dTime;		FILE *in;	PCS *myProcess, *myPcs1, *myPcs2;       	int endOfFile, rv;	char arv[20],rtm[15];		if (argc < 4) {		printf("The program needs 3 arguments of time in millosecond, 1st is context swithing, 2nd is time slice for rr, 3rd is the input file!\n");		exit(1);	}	printf("Arrive Time 		Start Time		Finish Time\n");	rv = atoi(argv[1]);	dTime=(float)rv/1000;		rv = atoi(argv[2]);		timeSlice = (float)rv/1000;		input = ListCreate();	readyQ = ListCreate();	in = fopen(argv[3], "r");		for (;;) {		myProcess = malloc(sizeof(PCS));		endOfFile=fscanf(in, "%s%s", arv, rtm);		if (endOfFile != EOF)		{			myProcess->arrive = atoi(arv);			myProcess->runtime = atof(rtm);			myProcess->unread = 1;			rv = ListPrepend(input, (void *)myProcess);		}		else {			fclose(in);			break;		}	}	myPcs1 = malloc(sizeof(PCS));	myPcs2 = malloc(sizeof(PCS));		for (;;) {	/* 4 cases with the ListCount of two lists*/		if (ListCount(input) > 0) {			if (ListCount(readyQ) > 0) {                     /*both nonempty, run a tSlice or remain runTime*/				myPcs1 = ListLast(input);				myPcs2 = ListTrim(readyQ);				if (myPcs2->unread == 1) {					myPcs2->unread=0;					myPcs2->startTime=totalTime;				}				if (myPcs2->runtime > timeSlice) {					myPcs2->runtime -= timeSlice;					totalTime += timeSlice;					if (myPcs1->arrive < totalTime) {	/*test if anything arrive druing the runtime, if yes, add it in front of the readyQ*/						myPcs1 = ListTrim(input);						rv = ListPrepend(readyQ, (void *)myPcs1);					}					rv = ListPrepend(readyQ, (void *)myPcs2);				}				else {					totalTime += myPcs2->runtime;					if (myPcs1->arrive < totalTime) {						myPcs1 = ListTrim(input);						rv = ListPrepend(readyQ, (void *)myPcs1);					}					printf("%d			%f		%f\n", myPcs2->arrive, myPcs2->startTime, totalTime);				}			}			else {                                                        /* arrive one*/				myPcs1 = ListTrim(input);				totalTime = (float) myPcs1->arrive;				rv = ListPrepend(readyQ, (void *)myPcs1);			}		}		else {                                                               /* no more arriving*/			if (ListCount(readyQ) > 0) {				myPcs2 = ListTrim(readyQ);				if (myPcs2->unread == 1) {					myPcs2->unread = 0;					myPcs2->startTime=totalTime;				}				if (myPcs2->runtime > timeSlice) {					myPcs2->runtime -= timeSlice;					totalTime += timeSlice;					rv = ListPrepend(readyQ, (void *)myPcs2);				}				else {					totalTime += myPcs2->runtime;					printf("%d			%f		%f\n", myPcs2->arrive, myPcs2->startTime, totalTime);				}			}			else break;                                                 /* both empty, done!*/		}		totalTime += dTime;	}	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -