zoukankan      html  css  js  c++  java
  • 实验二:作业调度模拟程序

    #include<stdio.h>
    #include<stdlib.h>
    typedef struct process_FCFS{
    	  char name;//进程名
    	  float arrivetime;//到达时间
    	  float servetime;//服务时间
    	  float finishtime;//完成时间
    	  float roundtime;//周转时间
    	  float daiquantime;//带权周转时间
    	  struct process_FCFS *link;//结构体指针 
    }FCFS;
    FCFS *p,*q,*head=NULL;  
    struct process_FCFS a[100];    
    FCFS inital(struct process_FCFS a[],int n); 
    void print(struct process_FCFS a[],int n); 
    void Fcfs(struct process_FCFS a[],int n);  
    struct process_FCFS *sortarrivetime(struct process_FCFS a[],int n);     
    //按到达时间进行冒泡排序  
    struct process_FCFS *sortarrivetime(struct process_FCFS a[],int n) 
    {   
    	int i,j;   
    	struct process_FCFS t;  
    	int flag;   
    	for(i=1;i<n;i++)  
    	{    
    		flag=0;    
    		for(j=0;j<n-i;j++)   
    		{     
    			if(a[j].arrivetime>a[j+1].arrivetime)    
    			{      
    				t=a[j];
    				a[j]=a[j+1];
    				a[j+1]=t;  
    				flag=1;//交换    
    			}   
    		}    
    		if(flag==0)//如果一趟排序中没发生任何交换,则排序结束    
    			break; 
     }   
    	return a; 
    }      
    //先来先服务算法  
    void Fcfs(struct process_FCFS a[],int n) 
    {   
    	int i;
    	a[0].finishtime=a[0].arrivetime+a[0].servetime;
    	a[0].roundtime=a[0].finishtime+a[0].arrivetime;
    	a[0].daiquantime=a[0].roundtime/a[0].servetime; 
    	for(i=0;i<n;i++)  
    	{    
    		if(a[i].arrivetime>a[i-1].finishtime)   
    		{ 
    			a[i].finishtime=a[i-1].finishtime+a[i].servetime;  
    			a[i].roundtime=a[i].finishtime-a[i].arrivetime;    
    			a[i].daiquantime=a[i].roundtime/a[i].servetime;   
    		}
    		else
    		{  
    			a[i].finishtime=a[i].arrivetime+a[i].servetime;  
    			a[i].roundtime=a[i].finishtime+a[i].arrivetime;  
    			a[i].daiquantime=a[i].roundtime/a[i].servetime;  
    		}    
    		printf("先来先服务
    ");
    		print(a,n);  
    	} 
    }   
    void print(struct process_FCFS a[],int n) 
    {   
    	int i;
    	for(i=0;i<n;i++)  
    	{   
    		printf("进程名:%c",a[i].name); 
    		printf("到达时间:%f",a[i].arrivetime); 
    		printf("服务时间:%f",a[i].servetime);   
    		printf("完成时间:%f",a[i].finishtime);  
    		printf("周转时间:%f",a[i].roundtime);  
    		printf("带权周转时间:%f",a[i].daiquantime); 
            printf("
    ");  
    } 
    }    
    //主函数
     void main()
     {   
    	 int n,i; 
    	 printf("请输入有几个进程
    ");  
    	 scanf("%d",&n); 
    	 for(i=0;i<n;i++)  
    	 {   
    		 printf("print %d process name:",i+1);  
    		 scanf("%c",&a[i].name);  
    		 printf("arrivetime");
    		 scanf("%f",&a[i].arrivetime); 
    		 printf("servetime");   
    		 scanf("%f",&a[i].servetime);
     }  
    	 Fcfs(a,n);
     } 
    

     

    只是完成了部分的先来先服务的算法,其他的算法还是不懂。

  • 相关阅读:
    【模拟7.22】方程的解(拓展欧几里德)
    Dijkstra堆优化模板
    7.19考后总结
    《机器学习实战》读书笔记
    从K近邻算法、距离度量谈到KD树、SIFT+BBF算法
    《c程序设计语言》-3.2 字符串转换
    《c程序设计语言》-3.1 判断语句多少影响时间
    《c程序设计语言》-2.10 不用if-else 转换大小写
    《c程序设计语言》-2.9
    《c程序设计语言》-2.6~2.8
  • 原文地址:https://www.cnblogs.com/woaiQ1314/p/4468110.html
Copyright © 2011-2022 走看看