操作系统原理与实验——实验十三多道批处理作业调度(作业不可移动)

news2024/11/16 21:56:12

关键代码

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct  data{
    int hour;//当前小时
    int min;//当前分钟
}time;
struct node{
    char name[20];//进程名
    time arrive;//到达就绪队列时间
    int zx;//执行时间(预期时间)
    int size;
    int tai;
    int flag;
    time zhuangru; 
    time start;//开始执行时间(进程调度)
    time finish;//执行完成时间
    int zz;//周转时间=完成时间-到达就绪队列时间
    float zzxs;//带权周转时间系数=周转时间/执行时间
    struct node* next;
};
//内存结构体

typedef struct memory_node{
    int size; //内存大小
    int address; //内存始址
} memoryNode;
memoryNode memory;
//分区结构体
struct link_node{
    int size;//分区大小
    int address; //分区始址
    char flag[20]; //分区状态,空闲或者占用作业名
    struct link_node *next;
};
int resource;
//函数名:in参数:无
node* in(){
//函数功能:输入访问序列信息
	int n;
	node *q,*head;
	head = NULL; 
	printf("请输入内存大小:");
	scanf("%d",&memory.size);
	printf("请输入起始地址大小为:");
	scanf("%d",&memory.address);
	printf("请输入磁带机资源:");
	scanf("%d",&resource); 
	printf("请输入进程数量:");
	scanf("%d",&n);
	printf("请输入进程的参数:\n"); 
	for(int i=0;i<n;i++)
	{
		node *p = (node *)malloc(sizeof(node));
		p->flag = 0;
		p->next = NULL;
		scanf("%s %d:%d %d分钟 %dK %d台",&p->name,&p->arrive.hour,&p->arrive.min,&p->zx,&p->size,&p->tai);
		if(head == NULL)
		{
			head = p;
			q = p;
		} 
		else
		{
			q->next = p;
			q = p;
		}
	}
	return head;
}

void output(node *p) {
    //函数功能:按进程执行顺序分别输出每个进程全部结果信息和系统平均时间
   int sum=0,count=0; 
   float sum1=0; 
   printf("\n模拟进程FCFS调度过程输出结果:\n作业名   到达时间   执行时间(分钟)    装入时间   开始时间   完成时间  周转时间(分钟)  带权周转系数\n");
   while(p!=NULL)
   {
    	printf("%5s ",p->name);
    	printf("%5d:%02d ",p->arrive.hour,p->arrive.min);
    	printf("%8d(分钟) ",p->zx);
    	printf("%14d:%02d ",p->zhuangru.hour,p->zhuangru.min);
    	printf("%6d:%02d ",p->start.hour,p->start.min);
    	printf("%7d:%02d ",p->finish.hour,p->finish.min);
    	printf("%7d ",p->zz);
    	printf("%20.2f\n",p->zzxs);
    	sum=sum+p->zz;
    	sum1=sum1+p->zzxs;
    	count++;
    	p=p->next;
   }
   printf("系统平均周转时间为:%.2f\n",sum*1.0/count);
   printf("系统平均带权周转系数为:%.2f\n\n",sum1/count);
}
//函数名:FCFS参数:无
void FCFS(){
//函数功能:调用先来先服务算法
	printf("\n***********FCFS多道批处理作业调度***********\n");
	node *head = in();
	node *h,*q;
	h = NULL;
	q = head;
	while(q!=NULL)
	{
		node *p = (node *)malloc(sizeof(node));
		*p = *q;
		p->next = NULL;
		if(h == NULL)
		{
			h = p;
		}
		else
		{
			node *a = h,*b;
			while(a!=NULL)
			{
				if(p->arrive.hour*60+p->arrive.min<a->arrive.hour*60+a->arrive.min)
				break;
				b = a;
				a = a->next;
			}
			if(a == h)
			{
				p->next = h;
				h = p;
			}
			else
			{
				p->next = a;
				b->next = p;
			}
		}
		q = q->next; 
	}
	
	time now;
	now.hour = 0;
	now.min = 0;
	int qaq = 0,available = resource;
	q = h;
	node *duilie = NULL,*flow,*flagh;
	node *k,*flowk,*KK=NULL; 
	link_node *wfp,*yfp,*bl1,*bl2,*bl1pre,*bl2pre;
	wfp = NULL;
	yfp = NULL;
	
	link_node* i = (link_node*)malloc(sizeof(link_node));
	i->address = memory.address;
	i->flag[0] = '\0';
	i->size = memory.size;
	i->next = NULL;
	wfp = i;
	
	bl1 = wfp;
	while(h!=NULL)
	{
		flagh = h;
		//每一次大循环都找在自己执行完的时间内并且符合条件的 摘下来 
		//大循环每次末尾都回收第一个 	
		q = h;
		if(duilie==NULL)
		{
			h = q->next;
			q->next = NULL;
			duilie = q;
			flow = duilie;
			if(duilie->arrive.hour*60+duilie->arrive.min>now.hour*60+now.min)
			{
				now.hour = duilie->arrive.hour;
				now.min = duilie->arrive.min;
			}
			duilie->start.hour = now.hour;
			duilie->start.min = now.min;
			duilie->zhuangru.hour = now.hour;
			duilie->zhuangru.min = now.min;
			
			link_node *i = (link_node *)malloc(sizeof(link_node));//分配给作业的结点 
			i->address = wfp->address;
			strcpy(i->flag,q->name);
			i->size = q->size;
			i->next = NULL;
			
			available -=q->tai;
			if(wfp->size==q->size)//修改未分配表 !!!!!
			{
				wfp = NULL;
			}
			else
			{
				wfp->address = wfp->address + q->size;
				wfp->size = wfp->size - q->size;
			}
			//修改已分配表 
			yfp = i; 
		}
		//如果不是第一个,则遍历去找符合条件的 
		node *hh = h,*hhpre;
		bl1 = wfp;
		while(hh!=NULL)
		{
			bl1 = wfp;
			while(bl1!=NULL)
			{	
				if(hh->size<=bl1->size)
				break;
				bl1pre = bl1;
				bl1=bl1->next;
			}

			if(hh->arrive.hour*60+hh->arrive.min<=duilie->start.hour*60+duilie->start.min+duilie->zx&&bl1!=NULL&&available-hh->tai>=0)
			{
				//满足条件 
				hh->start.hour = duilie->start.hour + (duilie->start.min + duilie->zx )/60;
				hh->start.min = (duilie->start.min + duilie->zx )%60;
				hh->zhuangru.hour = now.hour;
				hh->zhuangru.min = now.min;
				available -=hh->tai;
				link_node *i = (link_node *)malloc(sizeof(link_node));//分配给作业的结点 
				i->address = bl1->address;
				strcpy(i->flag,hh->name);
				i->size = hh->size;
				i->next = NULL;
				
				if(bl1 == wfp)//修改未分配表 
				{
					if(bl1->size==hh->size)
					{
						wfp = bl1->next;
						free(bl1);
					}
					else
					{
						bl1->address = bl1->address + hh->size;
						bl1->size = bl1->size - hh->size;
					}
				}
				else
				{
					if(bl1->size==hh->size)
					{
						bl1pre->next = bl1->next;
						free(bl1);
					}
					else
					{
						bl1->address = bl1->address + hh->size;
						bl1->size = bl1->size - hh->size;
					}
				}
				if(yfp == NULL)
				{
					yfp = i;
				}
				else
				{
					i->next = yfp;
					yfp = i;
				}
				
				if(hh==h)
				{
					h=hh->next;
					hh->next = NULL;
					if(duilie == NULL)
					{
						duilie = hh;
						flow = hh;
					}
					else
					{
						flow->next = hh;
						flow = hh;
					}
					hh = h;
				}
				else
				{
					hhpre->next = hh->next;
					hh->next = NULL;
					if(duilie == NULL)
					{
						duilie = hh;
						flow = hh;
					}
					else
					{
						flow->next = hh;
						flow = hh;
					}
					hh = hhpre->next;
				}
			}
			else
			{
				//不满足条件—————— 空间不满足 or 磁带机不满足
				hhpre = hh;
				hh=hh->next;
			}
		}
		//回收资源
		k=duilie;
		k->finish.hour = k->start.hour+(k->start.min+k->zx)/60;
		k->finish.min = (k->start.min + k->zx)%60;
		
		k->zz = k->finish.hour*60 + k->finish.min - (k->arrive.hour*60 + k->arrive.min);
		k->zzxs = k->zz*1.0/k->zx; 
		now.hour = k->finish.hour;
		now.min = k->finish.min;
		available +=k->tai;
		bl2 = yfp;
		while(bl2!=NULL)
		{
			if(strcmp(bl2->flag,duilie->name)==0)
			break;
			bl2pre = bl2;
			bl2 = bl2->next; 
		}
		if(bl2 == yfp)
		{
			yfp = bl2->next;
		}
		else
		{
			bl2pre->next = bl2->next;
		}
		bl2->flag[0] = '\0';
		bl2->next = NULL;
		bl1 = wfp;
		if(wfp==NULL)
		{
			wfp = bl2;
		}
		else
		while(bl1!=NULL)
		{
			if((bl2->address+bl2->size)<=wfp->address)//插头 
			{
				if(bl2->address+bl2->size<wfp->address)
				{
					bl2->flag[0] = '\0';
					bl2->next = wfp;
					wfp = bl2;
				}
				else
				{
					wfp->address = bl2->address;
					wfp->size = wfp->size + bl2->size;
					free(bl2);
				}
				break;
			}
			else if(bl1->next == NULL&&bl2->address>=bl1->address+bl1->size)//插尾
			{
				if(bl2->address>bl1->address+bl1->size)
				{
					bl2->flag[0] = '\0';
					bl2->next = NULL;
					bl1->next = bl2;
				}
				else
				{
					bl1->size = bl1->size + bl2->size;
					free(bl2);
				}
				break;
			} 
			else if(bl2->address+bl2->size<=bl1->address)//插中间 
			{
				if(bl1pre->address+bl1pre->size<bl2->address&&bl2->address+bl2->size<bl1->address)//没有上邻,没有下邻
				{
					bl2->next = bl1;
					bl1->next = bl2;
				}
				else if(bl1pre->address+bl1pre->size==bl2->address&&bl2->address+bl2->size<bl1->address)//有上邻,没有下邻
				{
					bl1pre->size = bl1pre->size + bl2->size;
					free(bl2);
				}
				else if(bl1pre->address+bl1pre->size<bl2->address&&bl2->address+bl2->size==bl1->address)//没有上邻,有下邻
				{
					bl1->address = bl2->address;
					bl1->size = bl1->size +bl2->size;
					free(bl2);
				}
				else if(bl1pre->address+bl1pre->size==bl2->address&&bl2->address+bl2->size==bl1->address)//有下邻,有下邻 
				{
					bl1pre->size = bl1pre->size + bl1->size + bl2->size;
					bl1pre->next = bl1->next;
					free(bl1);
					free(bl2);
				}
				break;
			} 
			bl1pre = bl1;
			bl1 = bl1->next;
		}
		duilie = duilie->next;
		if(KK==NULL)
		{
			KK=k;
			flowk = k;
			k->next = NULL;
		}
		else
		{
			flowk->next = k;
			flowk = k;
			k->next = NULL;
		}		
	}
	while(duilie!=NULL)//h==NULL但是duilie不等于NULL 
	{
		k=duilie;
		k->start.hour = now.hour;
		k->start.min = now.min;
		k->finish.hour = k->start.hour+(k->start.min+k->zx)/60;
		k->finish.min = (k->start.min + k->zx)%60;
		
		k->zz = k->finish.hour*60 + k->finish.min - (k->arrive.hour*60 + k->arrive.min);
		k->zzxs = k->zz*1.0/k->zx; 
		now.hour = k->finish.hour;
		now.min = k->finish.min;
		available +=k->tai;memory.size +=k->size;
		
		duilie = duilie->next;
		if(KK==NULL)
		{
			KK=k;
			flowk = k;
			k->next = NULL;
		}
		else
		{
			flowk->next = k;
			flowk = k;
			k->next = NULL;
		}
	}
	output(KK);
}
//函数名:SSTF参数:无
void SPF(){
//函数功能:调用短进程优先调度算法
	printf("\n***********SPF多道批处理作业调度***********\n");
	node *head = in();
	node *h,*q,*H;
	h = NULL;
	q = head;
	H = q;
	q = q->next;
	while(q!=NULL)
	{
		node *p = (node *)malloc(sizeof(node));
		*p = *q;
		p->next = NULL;
		if(h == NULL)
		{
			h = p;
		}
		else
		{
			node *a = h,*b;
			while(a!=NULL)
			{
				if(p->zx<a->zx)
				break;
				b = a;
				a = a->next;
			}
			if(a == h)
			{
				p->next = h;
				h = p;
			}
			else
			{
				p->next = a;
				b->next = p;
			}
		}
		q = q->next; 
	}
	H->next = h;
	h = H;
	
	time now;
	now.hour = 0;
	now.min = 0;
	int qaq = 0,available = resource;
	q = h;
	node *duilie = NULL,*flow,*flagh;
	node *k,*flowk,*KK=NULL; 
	link_node *wfp,*yfp,*bl1,*bl2,*bl1pre,*bl2pre;
	wfp = NULL;
	yfp = NULL;
	
	link_node* i = (link_node*)malloc(sizeof(link_node));
	i->address = memory.address;
	i->flag[0] = '\0';
	i->size = memory.size;
	i->next = NULL;
	wfp = i;
	
	bl1 = wfp;
	while(h!=NULL)
	{
		flagh = h;
		//每一次大循环都找在自己执行完的时间内并且符合条件的 摘下来 
		//大循环每次末尾都回收第一个 	
		q = h;
		if(duilie==NULL)
		{
			h = q->next;
			q->next = NULL;
			duilie = q;
			flow = duilie;
			if(duilie->arrive.hour*60+duilie->arrive.min>now.hour*60+now.min)
			{
				now.hour = duilie->arrive.hour;
				now.min = duilie->arrive.min;
			}
			duilie->start.hour = now.hour;
			duilie->start.min = now.min;
			duilie->zhuangru.hour = now.hour;
			duilie->zhuangru.min = now.min;
			
			link_node *i = (link_node *)malloc(sizeof(link_node));//分配给作业的结点 
			i->address = wfp->address;
			strcpy(i->flag,q->name);
			i->size = q->size;
			i->next = NULL;
			
			available -=q->tai;

			if(wfp->size==q->size)//修改未分配表 !!!!!
			{
				wfp = NULL;
			}
			else
			{
				wfp->address = wfp->address + q->size;
				wfp->size = wfp->size - q->size;
			}
			//修改已分配表 
			yfp = i; 
		}
		//如果不是第一个,则遍历去找符合条件的
		node *hh = h,*hhpre;
		bl1 = wfp;
		while(hh!=NULL)
		{
			bl1 = wfp;
			while(bl1!=NULL)
			{	
				if(hh->size<=bl1->size)
				break;
				bl1pre = bl1;
				bl1=bl1->next;
			}
			
			if(hh->arrive.hour*60+hh->arrive.min<=duilie->start.hour*60+duilie->start.min+duilie->zx&&bl1!=NULL&&available-hh->tai>=0)
			{
				//满足条件
				hh->start.hour = duilie->start.hour + (duilie->start.min + duilie->zx )/60;
				hh->start.min = (duilie->start.min + duilie->zx )%60;
				hh->zhuangru.hour = now.hour;
				hh->zhuangru.min = now.min;
				available -=hh->tai;
				link_node *i = (link_node *)malloc(sizeof(link_node));//分配给作业的结点 
				i->address = bl1->address;
				strcpy(i->flag,hh->name);
				i->size = hh->size;
				i->next = NULL;
				
				if(bl1 == wfp)//修改未分配表 
				{
					if(bl1->size==hh->size)
					{
						wfp = bl1->next;
						free(bl1);
					}
					else
					{
						bl1->address = bl1->address + hh->size;
						bl1->size = bl1->size - hh->size;
					}
				}
				else
				{
					if(bl1->size==hh->size)
					{
						bl1pre->next = bl1->next;
						free(bl1);
					}
					else
					{
						bl1->address = bl1->address + hh->size;
						bl1->size = bl1->size - hh->size;
					}
				}
				if(yfp == NULL)
				{
					yfp = i;
				}
				else
				{
					i->next = yfp;
					yfp = i;
				}
				
				if(hh==h)
				{
					h=hh->next;
					hh->next = NULL;
					if(duilie == NULL)
					{
						duilie = hh;
						flow = hh;
					}
					else
					{
						flow->next = hh;
						flow = hh;
					}
					hh = h;
				}
				else
				{
					hhpre->next = hh->next;
					hh->next = NULL;
					if(duilie == NULL)
					{
						duilie = hh;
						flow = hh;
					}
					else
					{
						flow->next = hh;
						flow = hh;
					}
					hh = hhpre->next;
				}
			}
			else
			{
				//不满足条件——————>空间不满足  or  磁带机不满足
				hhpre = hh;
				hh=hh->next;
			}
		}
		//回收资源
		k=duilie;
		k->finish.hour = k->start.hour+(k->start.min+k->zx)/60;
		k->finish.min = (k->start.min + k->zx)%60;
		
		k->zz = k->finish.hour*60 + k->finish.min - (k->arrive.hour*60 + k->arrive.min);
		k->zzxs = k->zz*1.0/k->zx; 
		now.hour = k->finish.hour;
		now.min = k->finish.min;
		available +=k->tai;
		bl2 = yfp;
		while(bl2!=NULL)
		{
			if(strcmp(bl2->flag,duilie->name)==0)
			break;
			bl2pre = bl2;
			bl2 = bl2->next; 
		}
		if(bl2 == yfp)
		{
			yfp = bl2->next;
		}
		else
		{
			bl2pre->next = bl2->next;
		}
		bl2->flag[0] = '\0';
		bl2->next = NULL;
		bl1 = wfp;
		if(wfp==NULL)
		{
			wfp = bl2;
		}
		else
		while(bl1!=NULL)
		{
			if((bl2->address+bl2->size)<=wfp->address)//插头 
			{
				if(bl2->address+bl2->size<wfp->address)
				{
					bl2->flag[0] = '\0';
					bl2->next = wfp;
					wfp = bl2;
				}
				else
				{
					wfp->address = bl2->address;
					wfp->size = wfp->size + bl2->size;
					free(bl2);
				}
				break;
			}
			else if(bl1->next == NULL&&bl2->address>=bl1->address+bl1->size)//插尾
			{
				if(bl2->address>bl1->address+bl1->size)
				{
					bl2->flag[0] = '\0';
					bl2->next = NULL;
					bl1->next = bl2;
				}
				else
				{
					bl1->size = bl1->size + bl2->size;
					free(bl2);
				}
				break;
			} 
			else if(bl2->address+bl2->size<=bl1->address)//插中间 
			{
				if(bl1pre->address+bl1pre->size<bl2->address&&bl2->address+bl2->size<bl1->address)//没有上邻,没有下邻
				{
					bl2->next = bl1;
					bl1->next = bl2;
				}
				else if(bl1pre->address+bl1pre->size==bl2->address&&bl2->address+bl2->size<bl1->address)//有上邻,没有下邻
				{
					bl1pre->size = bl1pre->size + bl2->size;
					free(bl2);
				}
				else if(bl1pre->address+bl1pre->size<bl2->address&&bl2->address+bl2->size==bl1->address)//没有上邻,有下邻
				{
					bl1->address = bl2->address;
					bl1->size = bl1->size +bl2->size;
					free(bl2);
				}
				else if(bl1pre->address+bl1pre->size==bl2->address&&bl2->address+bl2->size==bl1->address)//有下邻,有下邻 
				{
					bl1pre->size = bl1pre->size + bl1->size + bl2->size;
					bl1pre->next = bl1->next;
					free(bl1);
					free(bl2);
				}
				break;
			} 
			bl1pre = bl1;
			bl1 = bl1->next;
		}
		duilie = duilie->next;
		if(KK==NULL)
		{
			KK=k;
			flowk = k;
			k->next = NULL;
		}
		else
		{
			flowk->next = k;
			flowk = k;
			k->next = NULL;
		}		
	}
	while(duilie!=NULL)//h==NULL但是duilie不等于NULL 
	{
		k=duilie;
		k->start.hour = now.hour;
		k->start.min = now.min;
		k->finish.hour = k->start.hour+(k->start.min+k->zx)/60;
		k->finish.min = (k->start.min + k->zx)%60;
		
		k->zz = k->finish.hour*60 + k->finish.min - (k->arrive.hour*60 + k->arrive.min);
		k->zzxs = k->zz*1.0/k->zx; 
		now.hour = k->finish.hour;
		now.min = k->finish.min;
		available +=k->tai;memory.size +=k->size;
		
		duilie = duilie->next;
		if(KK==NULL)
		{
			KK=k;
			flowk = k;
			k->next = NULL;
		}
		else
		{
			flowk->next = k;
			flowk = k;
			k->next = NULL;
		}
	}
	output(KK);
}
//函数名:Elevator参数:无
void HRRF(){
//函数功能:调用电梯调度算法
	printf("\n***********HRRF多道批处理作业调度***********\n");
	node *head = in();
	node *h,*q;
	h = NULL;
	q = head;
	while(q!=NULL)
	{
		node *p = (node *)malloc(sizeof(node));
		*p = *q;
		p->next = NULL;
		if(h == NULL)
		{
			h = p;
		}
		else
		{
			node *a = h,*b;
			while(a!=NULL)
			{
				if(p->arrive.hour*60+p->arrive.min<a->arrive.hour*60+a->arrive.min)
				break;
				b = a;
				a = a->next;
			}
			if(a == h)
			{
				p->next = h;
				h = p;
			}
			else
			{
				p->next = a;
				b->next = p;
			}
		}
		q = q->next; 
	}
	
	time now;
	now.hour = 0;
	now.min = 0;
	int qaq = 0,available = resource,flag=0;
	q = h;
	node *duilie = NULL,*flow,*flagh;
	node *k,*flowk,*KK=NULL; 
	link_node *wfp,*yfp,*bl1,*bl2,*bl1pre,*bl2pre;
	wfp = NULL;
	yfp = NULL;
	
	link_node* i = (link_node*)malloc(sizeof(link_node));
	i->address = memory.address;
	i->flag[0] = '\0';
	i->size = memory.size;
	i->next = NULL;
	wfp = i;
	
	bl1 = wfp;
	while(h!=NULL)
	{
		flagh = h;
		//每一次大循环都找在自己执行完的时间内并且符合条件的 摘下来 
		//大循环每次末尾都回收第一个 			
		q = h;
		if(flag==0)
		{	
			flag=1;
			node *first = h,*b = h;
			while(b!=NULL)
			{
				if(b->arrive.hour*60+b->arrive.min<first->arrive.hour*60+first->arrive.min)
				first = b;
				b = b->next; 
			} 
			b = h;
			while(b!=NULL)
			{
				if(b->next == first)
				break;
				b = b->next;
			}
			if(first == h)
			{
				h = first->next;
				first->next = NULL;
				duilie = first;
			}
			else
			{
				b->next = first->next;
				first->next = NULL;
				duilie = first;
			}
			flow = duilie;
			now.hour = duilie->arrive.hour;
			now.min = duilie->arrive.min;
			
			duilie->start.hour = now.hour;
			duilie->start.min = now.min;
			duilie->zhuangru.hour = now.hour;
			duilie->zhuangru.min = now.min;
			now.hour = duilie->start.hour + (duilie->start.min + duilie->zx)/60;
			now.min =  (duilie->start.min + duilie->zx)%60;
			duilie->finish.hour = now.hour;
			duilie->finish.min = now.min;
			
			duilie->zz = duilie->finish.hour*60 + duilie->finish.min - (duilie->arrive.hour*60 + duilie->arrive.min);
			duilie->zzxs = duilie->zz*1.0/duilie->zx; 
			
			duilie  = duilie->next;
			KK = flow;
			flowk = KK;	
		}
		 q = h;
		 node *xyb=NULL;
	while(q!=NULL)
	{
		node *p = (node *)malloc(sizeof(node));
		*p = *q;
		p->next = NULL;
		if(xyb == NULL)
		{
			xyb = p;
		}
		else
		{
			node *a = xyb,*b;
			while(a!=NULL)
			{
				if((now.hour*60+now.min-q->arrive.hour*60-q->arrive.min+q->zx)*1.0/q->zx>(now.hour*60+now.min-a->arrive.hour*60-a->arrive.min+a->zx)*1.0/a->zx)
				break;
				b = a;
				a = a->next;
			}
			if(a == xyb)
			{
				p->next = xyb;
				xyb = p;
			}
			else
			{
				p->next = a;
				b->next = p;
			}
		}
		q = q->next; 
	}
	//如果不是第一个,则遍历去找符合条件的
		node *hh = xyb,*hhpre;
		bl1 = wfp;
		while(hh!=NULL)
		{
			bl1 = wfp;
			while(bl1!=NULL)
			{	
				if(hh->size<=bl1->size)
				break;
				bl1pre = bl1;
				bl1=bl1->next;
			}
			if(bl1!=NULL&&available-hh->tai>=0)
			{
				//满足条件 
				available -=hh->tai;
				link_node *i = (link_node *)malloc(sizeof(link_node));//分配给作业的结点 
				i->address = bl1->address;
				strcpy(i->flag,hh->name);
				i->size = hh->size;
				i->next = NULL;
				
				if(bl1 == wfp)//修改未分配表 
				{
					if(bl1->size==hh->size)
					{
						wfp = bl1->next;
						free(bl1);
					}
					else
					{
						bl1->address = bl1->address + hh->size;
						bl1->size = bl1->size - hh->size;
					}
				}
				else
				{
					if(bl1->size==hh->size)
					{
						bl1pre->next = bl1->next;
						free(bl1);
					}
					else
					{
						bl1->address = bl1->address + hh->size;
						bl1->size = bl1->size - hh->size;
					}
				}
				if(yfp == NULL)
				{
					yfp = i;
				}
				else
				{
					i->next = yfp;
					yfp = i;
				}

				node *xybh = h,*xybhpre;
				while(xybh!=NULL)
				{
					if(strcmp(xybh->name,hh->name) == 0)
					{
						xybh->zhuangru.hour = now.hour;
						xybh->zhuangru.min = now.min;
						break;
					}
					xybhpre = xybh;
					xybh = xybh->next;
				}
				if(xybh == h)
				{
					h = h->next;
					xybh->next = NULL;
					if(duilie == NULL)
					{ 
						duilie = xybh;
						flow = xybh; 
					} 
					else
					{
						flow->next = xybh;
						flow = xybh;
					}
				}
				else
				{
					xybhpre->next = xybh->next;
					xybh->next = NULL;
					if(duilie == NULL)
					{ 
						duilie = xybh;
						flow = xybh; 
					} 
					else
					{
						flow->next = xybh;
						flow = xybh;
					} 
				}
			}
				//否则不满足条件——————> 空间不满足 or  磁带机不满足
			hh = hh->next;
			
		}
		//回收资源
		k=duilie;
		k->start.hour = now.hour;
		k->start.min = now.min;
		k->finish.hour = k->start.hour+(k->start.min+k->zx)/60;
		k->finish.min = (k->start.min + k->zx)%60;
		
		k->zz = k->finish.hour*60 + k->finish.min - (k->arrive.hour*60 + k->arrive.min);
		k->zzxs = k->zz*1.0/k->zx; 
		now.hour = k->finish.hour;
		now.min = k->finish.min;
		available +=k->tai;
		bl2 = yfp;
		while(bl2!=NULL)
		{
			if(strcmp(bl2->flag,duilie->name)==0)
			break;
			bl2pre = bl2;
			bl2 = bl2->next; 
		}
		if(bl2 == yfp)
		{
			yfp = bl2->next;
		}
		else
		{
			bl2pre->next = bl2->next;
		}
		bl2->flag[0] = '\0';
		bl2->next = NULL;
		bl1 = wfp;
		if(wfp==NULL)
		{
			wfp = bl2;
		}
		else
		while(bl1!=NULL)
		{
			if((bl2->address+bl2->size)<=wfp->address)//插头 
			{ 
				if(bl2->address+bl2->size<wfp->address)
				{
					bl2->flag[0] = '\0';
					bl2->next = wfp;
					wfp = bl2;
				}
				else
				{
					wfp->address = bl2->address;
					wfp->size = wfp->size + bl2->size;
					free(bl2);
				}
				break;
			}
			else if(bl1->next == NULL&&bl2->address>=bl1->address+bl1->size)//插尾
			{
				if(bl2->address>bl1->address+bl1->size)
				{
					bl2->flag[0] = '\0';
					bl2->next = NULL;
					bl1->next = bl2;
				}
				else
				{
					bl1->size = bl1->size + bl2->size;
					free(bl2);
				}
				break;
			} 
			//else if()
			else if(bl2->address+bl2->size<=bl1->address)//插中间 
			{
				if(bl1pre->address+bl1pre->size<bl2->address&&bl2->address+bl2->size<bl1->address)//没有上邻,没有下邻
				{
					bl2->next = bl1;
					bl1->next = bl2;
				}
				else if(bl1pre->address+bl1pre->size==bl2->address&&bl2->address+bl2->size<bl1->address)//有上邻,没有下邻
				{
					bl1pre->size = bl1pre->size + bl2->size;
					free(bl2);
				}
				else if(bl1pre->address+bl1pre->size<bl2->address&&bl2->address+bl2->size==bl1->address)//没有上邻,有下邻
				{
					bl1->address = bl2->address;
					bl1->size = bl1->size +bl2->size;
					free(bl2);
				}
				else if(bl1pre->address+bl1pre->size==bl2->address&&bl2->address+bl2->size==bl1->address)//有下邻,有下邻 
				{
					bl1pre->size = bl1pre->size + bl1->size + bl2->size;
					bl1pre->next = bl1->next;
					free(bl1);
					free(bl2);
				}
				break;
			} 
			bl1pre = bl1;
			bl1 = bl1->next;
		}
		duilie = duilie->next;
		if(KK==NULL)
		{
			KK=k;
			flowk = k;
			k->next = NULL;
		}
		else
		{
			flowk->next = k;
			flowk = k;
			k->next = NULL;
		}		
	}
	while(duilie!=NULL)//h==NULL但是duilie不等于NULL 
	{
		k=duilie;
		k->start.hour = now.hour;
		k->start.min = now.min;
		k->finish.hour = k->start.hour+(k->start.min+k->zx)/60;
		k->finish.min = (k->start.min + k->zx)%60;
		
		k->zz = k->finish.hour*60 + k->finish.min - (k->arrive.hour*60 + k->arrive.min);
		k->zzxs = k->zz*1.0/k->zx; 
		now.hour = k->finish.hour;
		now.min = k->finish.min;
		available +=k->tai;memory.size +=k->size;
		
		duilie = duilie->next;
		if(KK==NULL)
		{
			KK=k;
			flowk = k;
			k->next = NULL;
		}
		else
		{
			flowk->next = k;
			flowk = k;
			k->next = NULL;
		}
	}
	output(KK);
}

//函数名:Out参数:无
void Out(){
//函数功能:输出选项菜单
	printf("***************多道批处理作业调度***************\n");
	printf("  *        1.先来先服务调度算法(FCFS)          *\n");
	printf("  *        2.最短作业优先算法(SPF)             *\n");
	printf("  *        3.响应比最高者优先算法(HRRF)        *\n");
	printf("  *        0.退出                              *\n");
	printf("           请输入选项[ ]\b\b");
}
int main()
{
    while (1)
    {
        Out();//给出选项
        int c;
        scanf("%d", &c);
        switch (c){//选择算法
        case 1:FCFS();
            break;
        case 2:SPF();
            break;
        case 3:HRRF();
            break;
        default:printf("\n调度结束!");
            exit(1);
        }
    }
    return 0;
}

实验结果

实验总结

①处理单链表还是不熟练;

②对操作哪个单链表模糊,导致结果错误;

③C语言没有return不报错;

④p=q不等价与*p=*q;

⑤宏观上并行,微观上串行;先释放在申请。

tips:本题思路

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1656295.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

用栈实现队列——leetcode刷题

题目要求我们只用栈的基本操作 push to top 入栈&#xff0c;peek from top 返回栈顶元素&#xff0c;pop from top 移除并返回栈顶元素&#xff0c;size 栈的大小&#xff0c;is_empty 判断栈是否为空&#xff0c;这几个函数来实现队列&#xff0c;也就是说&#xff0c;我们在…

建议收藏!如何选择高低温冲击试验箱厂家?

高低温冲击试验箱是实验室中不可或缺的重要设备之一&#xff0c;它在许多领域都发挥着关键作用。因此选择合适的高低温冲击试验箱厂家是非常关键的&#xff0c;因为正规厂家的正规产品能直接影响到产品实验的准确性和效率。下面我们一起来了解一下关于选择高低温冲击试验箱厂家…

从源头把控风险:集团多主体合规管理实战技巧分享

官.网地址&#xff1a;合合TextIn - 合合信息旗下OCR云服务产品 集团合规管理中&#xff0c;为了规避内外部利益冲突&#xff0c;需要对员工、供应商、经销商、客户、黑名单企业等多主体及其关联主体之间&#xff0c;进行多维度、多层级的关系挖掘与排查&#xff0c;避免利益…

OpenHarmony 实战开发(南向)-Docker编译环境搭建

Docker环境介绍 OpenHarmony为开发者提供了两种Docker环境&#xff0c;以帮助开发者快速完成复杂的开发环境准备工作。两种Docker环境及适用场景如下&#xff1a; 独立Docker环境&#xff1a;适用于直接基于Ubuntu、Windows操作系统平台进行版本编译的场景。 基于HPM的Docker…

react、vue 把要渲染的元素挂到指定节点。

react、vue 把要渲染的元素挂到指定节点。 文章目录 vue3 的 Teleportreact 的 createPortal 在日常工作中&#xff0c;需要封装一些定制的浮动模态框&#xff0c;但是每个弹框在不同的父级元素中&#xff0c;那弹框的层级我们是没有办法控制到的&#xff0c;所有有必要把它统一…

2024年钉钉直播回放怎么永久保存

钉钉群直播回放下载工具我已经打包好了&#xff0c; 钉钉群直播回放下载链接&#xff1a;百度网盘 请输入提取码 提取码&#xff1a;1234 --来自百度网盘超级会员V10的分享 1.首先解压好我给大家准备好的压缩包 2.再继续解压M3U8逍遥一仙下载器 3.进入M3U8逍遥一仙下载器文…

Pytorch快速上手

Pytorch快速上手 一、加载数据集 &#xff08;Dataset&#xff09; 加载数据集需要继承Dataset&#xff0c;通常情况下需要实现__init__方法、__getitem__方法以及__len__方法。 案例一&#xff1a; import osimport torch from torch.utils.data import Dataset from PIL …

SqlDeveloper字体大小设置

菜单栏字体&#xff1a; C:\Users\xxx\AppData\Roaming\SQL Developer\system19.2.1.247.2212\o.sqldeveloper 下的ide.properties 修改 Ide.FontSize.Aqua30 编辑器字体&#xff1a;

特定消谐技术:SHEPWM调制方法

简介 特定消谐技术是通过计算PWM波的开关时刻&#xff0c;消除特定的低阶谐波。其基本理论是恰当地控制逆变器脉宽调制电压的波形&#xff0c;通过脉宽平均法把逆变器输出的方波电压转换成等效的正弦波&#xff0c;以消除某些特定的谐波。本文对特定谐波消除方法的基本原理进行…

SpringBoot启动流程源码解析

目录 一、SpringApplication构造方法解析 1. web应用类型 2. BootstrapRegistryInitializer 3. ApplicationContextInitializer 4. ApplicationListener 5. 推断Main方法所在类 二、SpringApplication.run(String... args)方法解析 1.创建DefaultBootstrapContext 2.获…

算法day02

1、202. 快乐数 如上题所述&#xff1a; 在该题意规则下&#xff0c;所有的数字变化会有两种情况&#xff0c;其一最后是有的会变化成恒为1的数&#xff1b;其二是有的数会变化会呈现成有规律的环&#xff0c;分别如下图所示&#xff1a; 可以近似的理解为图一就是一个环&#…

Oracle 23ai rpm安装配置及问题处理

1.安装介质下载 Oracle 23ai 免费版本已经正式发布&#xff0c;Oracle官网提供免费的下载试用&#xff08;无需账号&#xff09;地址如下 官网下载和试用地址 Oracle Database 23ai Free&#xff1a; https://www.oracle.com/database/free/get-started 三种安装方式可选…

Cheetah3D for Mac - 轻松打造专业级3D作品

对于追求专业级3D作品的设计师来说&#xff0c;Cheetah3D for Mac无疑是一款不可多得的工具。 这款软件拥有强大的建模、渲染和动画功能&#xff0c;能够满足您在3D设计方面的各种需求。通过简单的操作&#xff0c;您可以轻松构建出复杂的3D模型&#xff0c;并为其添加逼真的材…

js自定义实现类似锚点(内容部分滚动)

场景&#xff1a; 效果图如上&#xff0c;类似锚点&#xff0c;但是屏幕不滚动。高度计算我不是很熟练。for循环写的比较麻烦。element plus 和Ant Design有类似组件效果。 html&#xff1a; <template><div><div style"height: 400px;" class&q…

新手如何便捷使用HTTP代理

便捷地使用HTTP代理主要涉及到设置和使用两个步骤。下面是在不同环境和使用场景下如何设置和使用HTTP代理的详细介绍: 1.浏览器设置: 打开浏览器的设置菜单&#xff0c;找到网络设置或代理设置的选项。在代理设置中&#xff0c;填写代理服务器的地址和端口号。不同的浏览器设…

Springboot+vue项目影城管理系统

摘 要 本论文主要论述了如何使用JAVA语言开发一个影城管理系统&#xff0c;本系统将严格按照软件开发流程进行各个阶段的工作&#xff0c;采用B/S架构&#xff0c;面向对象编程思想进行项目开发。在引言中&#xff0c;作者将论述影城管理系统的当前背景以及系统开发的目的&…

vue3+ant design实现表格数据导出Excel

提示:实现表格数据导出Excel 文章目录 前言 一、安装ant design? 二、引用ant design 1.搭建框架 2.获取表格数据 三、封装导出表格的代码 四、导出 1.获取导出地址 2.在下载导出事件中添加导出代码 五、全部代码 前言 今天终于有时间来更新文章了,最近公司项目比较紧…

图:广度优先遍历(BFS)和深度优先遍历(DFS)

1.工具类&#xff1a;队列和字典 export class DictionNary {// 字典的封装constructor() {this.items {}}set(key, value) {// 添加键this.items[key] value}has(key){// 判断键是否存在return this.items.hasOwnProperty(key)}get(key){// 获取键的valuereturn this.has(k…

民航电子数据库:数据库的备份与恢复

目录 前言备份库级逻辑备份示例 恢复库级的逻辑恢复示例 前言 民航电子数据库的备份与恢复 备份 库级逻辑备份 备份目标库下所有的对象 。 因此 &#xff0c;库级逻辑备份需要由备份库的管理员&#xff08;SYSDBA&#xff09;登录至备份目标库进行操作。 语法格式 &#xff1…

粤港澳青少年信息学创新大赛 Python 编程竞赛(初中部分知识点整理)

一、考试大纲梳理 知识内容 知识目标 计算机基础与编程环境&#xff0c;历史&#xff0c;存储与网络变量定义和使用基本数据类型&#xff08;整型&#xff0c;浮点型&#xff0c;字符型&#xff0c;布尔型&#xff09;&#xff0c;数据类型的转换控制语句结构&#xff08;顺序…