资源预览内容
第1页 / 共19页
第2页 / 共19页
第3页 / 共19页
第4页 / 共19页
第5页 / 共19页
第6页 / 共19页
第7页 / 共19页
第8页 / 共19页
第9页 / 共19页
第10页 / 共19页
亲,该文档总共19页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
#include#include#includeint memoryStartAddress = -1;int memorySize = -1;struct jobListint id; /* 作业ID */int size; /* 作业大小(需要的存储空间大小) */int status; /* 作业状态 0 : new job ,1 : in the memory , 2 : finished . */struct jobList *next; /* 作业链表指针 */;struct freeListint startAddress; /* 分区起始地址 */int size; /* 分区大小 */struct freeList *next; /* 分区链表指针 */;struct usedList int startAddress; /* 分区起始地址 */int jobID; /* 分区中存放作业ID */struct usedList *next; /* 分区链表指针 */;void errorMessage(void) /*出现严重错误时显示信息并结束程序*/printf(ntError !a);printf(nPress any key to exit !);getch();exit(1);void openFile(FILE *fp,char *filename,char *mode) /*以要求的方式打开文件*/if(*fp = fopen(filename,mode) = NULL)printf(nCant open %s in mode %s.,filename,mode);errorMessage();void makeFreeNode(struct freeList *empty,int startAddress,int size) /*根据参数startAddress、size创建空闲节点,由empty指针返回*/if(*empty = malloc(sizeof(struct freeList) = NULL)printf(nNot enough to allocate for the free node .);errorMessage();(*empty)-startAddress = startAddress;(*empty)-size = size;(*empty)-next = NULL;void iniMemory(void) /*初始化存储空间起始地址、大小*/char MSA10,MS10;printf(nPlease input the start address of the memory !);scanf(%s,MSA);memoryStartAddress = atoi(MSA);printf(nPlease input the size of the memory !);scanf(%s,MS);memorySize = atoi(MS);char selectFitMethod(void) /*选择适应算法*/FILE *fp;char fitMethod;doprintf(nnPlease input a char as fallow to select the fit method !n 1 (Best fit) n 2 (Worst fit) n 3 (First fit) n 4 (Last fit)n);fitMethod = getche();while(fitMethod 4); openFile(&fp,d:result.cl,a);switch(fitMethod)case 1: fprintf(fp,nnnntBest fit); fprintf(fp,n*); break;case 2: fprintf(fp,nnnntWorst fit); fprintf(fp,n*); break;case 3: fprintf(fp,nnnntFirst fit); fprintf(fp,n*); break;case 4: fprintf(fp,nnnntLast fit); fprintf(fp,n*); break;fclose(fp);return fitMethod;void inputJob(void) /*从键盘输入作业到D盘的JOB文件*/int /*id,size, */status = 0,jobnum = 0;FILE *fp;char id10,size10;openFile(&fp,d:job.cl,w);fprintf(fp,job_IDtsizetstatus);printf(nnnnPlease input the jobs as fallow !nEnter a integer smaller than 1 to quit .njob_IDtsizen);do/*scanf(%d%d,&id,&size); */scanf(%st%s,id,size);if(atoi(id) 0 & atoi(size) 0)fprintf(fp,n%st%st%d,id,size,status);/*fprintf(fp,n%dt%dt%d,id,size,status); */jobnum+;elsebreak;while(1);if(jobnum)printf(nFinished to input the jobs !);elseprintf(nNo job was given .);errorMessage();fclose(fp);int makeJobList(struct jobList *jobs) /*从JOB文件中读出作业并创建作业链表*/char jobID10,size10,status10;struct jobList *rear;FILE *fp;openFile(&fp,d:job.cl,r);fscanf(fp,%s%s%s,jobID,size,status);if(*jobs = malloc(sizeof(struct jobList) = NULL)printf(nNot enough to allocate for the job .);fclose(fp);errorMessage();rear = *jobs;(*jobs)-next = NULL;while(!feof(fp)struct jobList *p;fscanf(fp,%s%s%s,jobID,size,status);if(p = malloc(sizeof(struct jobList) = NULL)printf(nNot enough to allocate for the job .);fclose(fp);errorMessage();p - next = rear - next;rear - next = p;rear = rear - next;rear - id = atoi(jobID);rear - size = atoi(size);rear - status = atoi(status);fclose(fp);return 0;int updateJobFile(struct jobList *jobs) /*更新作业链表中作业的状态*/FILE *fp;struct jobList *p;openFile(&fp,d:job.cl,w);fprintf(fp,job_IDtsizetstatus);for(p = jobs - next;p;p = p - next)fprintf(fp,n%dt%dt%d,p-id,p-size,p-status);fclose(fp);return 0;int showFreeList(struct freeList *empty) /*空闲分区队列显示*/FILE *fp;struct freeList *p = empty - next;int count = 0;openFile(&fp,d:result.cl,a);fprintf(fp,nnNow show the free list.);printf(nnNow show the free list.);if(p)fprintf(fp,nnumbertsizetstartAddress);printf(nnumbertsizetstartAddress);for(;p;p = p - next)fprintf(fp,n%dt%dt%d,+co
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号