// zuoye.cpp : Defines the entry point for the console application.
//

#include <iostream.h>
#define WorkMAX 20
//---------------------------------------------------------
typedef struct zuoye                 /*作业控制快*/
   {char name;                       /*作业名*/
    float handintime;                /*提交时间*/              
    float runtime;                   /*运行时间*/
    int workspace;                   /*工作空间*/
    float starttime;                 /*开始时间*/
    float finishtime;                /*完成时间*/
    float T;                         /*周转时间*/
    float W;                         /*带权周转时间*/
    char condition;                  /*状态*/
   }JCB;
//---------------------------------------------------------
void turn_func(JCB work[WorkMAX],int i,int j) /*交换位置*/
{JCB bridge;
bridge=work[i];
work[i]=work[j];
work[j]=bridge;
}
//--------------------------------------------------------
int input_func(JCB work[WorkMAX])            /*输入函数*/
{int n,i,j;
cout<<"please input the work number:"<<endl; /*作业个数*/
cin>>n;
cout<<"please input the works message"<<endl; /*作业信息*/
cout<<"Workname Handintime Runtime:"<<endl;
for(i=0;i<n;i++)
  {cin>>work[i].name;
   cin>>work[i].handintime;
   cin>>work[i].runtime;
   work[i].condition='W';
  }
for(i=0;i<n-1;i++)                      /*按时间先后排序*/
     for(j=i+1;j<n;j++)
         if(work[i].handintime>work[j].handintime)
             turn_func(work,i,j);
return n;
}
//--------------------------------------------------------
int Fselect_func(JCB work[WorkMAX],int n,int s0)/*先来先服务*/
{int i,s1,nostop;
for(nostop=1,i=0;i<n&&nostop;i++)
   if(work[i].condition=='W')
     {s1=i;nostop=0;}
  return s1;
}
//-----------------------------------------------------------
int Sselect_func(JCB work[WorkMAX],int n,int s0)/*短作业优先*/
{int i,j,s1,count,nostop,a[WorkMAX];
for(nostop=1,i=0;i<n&&nostop;i++)
   if(work[i].condition=='W')
     {s1=i;nostop=0;}
if(s0!=-1)
{
     for(j=0,i=0;i<n;i++)
         if(work[i].condition=='W'&&work[i].handintime<=work[s0].finishtime)      
         {
            a[j]=i;
            j++;                  
         }
      count=j;
      if(count>1)
      {
        s1=a[0];
        for(j=1;j<count;j++)
            if(work[a[j]].runtime<work[s1].runtime)
               s1=a[j];
      }
}
return s1;
}


//下接 计算机操作系统实验—作业调度(2)