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

📄 pcb.cpp

📁 处理机调度
💻 CPP
字号:
#include "PCB.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
 /*attern:this algorithm only has effets while the pcbList with an empty head*/
 void sortPCB(PCBList inPCBList)
 {
 		ptrPCBNode outerP,innerP,a,b;		
 		int flag=1;
 		if(inPCBList==NULL||inPCBList->next==NULL)
 			{
 				printf("in sortPCB,inPCBList is null\n");
 			}
 		outerP=inPCBList;
 		
 		while(outerP->next!=NULL)
 		{
 			flag=1;
			innerP=inPCBList;

				//Correction: should be:while(p->next!=NULL&&p->next->next!=NULL)//in C Language Usage.
 			while(innerP->next!=NULL&&innerP->next->next!=NULL)//Correction: not innerP->next!=NULL
 				{
 					if(innerP->next->priorityNum>innerP->next->next->priorityNum)
 					{	flag=0;
 						a=innerP->next;
 						b=innerP->next->next;
 						a->next=b->next;
 						innerP->next=b;
 						b->next=a;
						innerP=a;//Correction: add this to re point to new pos of innerP. 
 					}
					else
						innerP=innerP->next;
				}
			
			if(flag)
				break;	
			outerP=outerP->next;
		}
 	}
 	
 	void updatePCBList(PCBList pcbList,ptrProcess runProcess)
	{	
			PCBList tmpNode;
			tmpNode=pcbList;
			tmpNode=tmpNode->next;
			if(tmpNode==NULL||runProcess==NULL)
			{		printf("in updataPCBList,null ptr pass in\n!");return;}
			while(tmpNode!=NULL)
			{
				if(tmpNode->processID==runProcess->processID)
				{
						tmpNode->remainSecs=runProcess->remainSecs;
						tmpNode->priorityNum=runProcess->priorityNum;
						tmpNode->staturs=runProcess->staturs;
						strcpy(tmpNode->processName,runProcess->processName);
						break;
				}
				tmpNode=tmpNode->next;
			}
	}

⌨️ 快捷键说明

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