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

#include <iostream.h>

#ifndef NULL
  #define NULL  0
#endif
#define MAXP 20                                    /*最大进程数*/
//--------------------------------------------------------------------
typedef struct jincheng                            /*进程控制快*/
   {
    char name;                                      /*进程名*/
    int grade;                                      /*优先级*/
    int arrive;                                     /*到达时间*/
    int serve;                                      /*服务时间*/
    int condition;                                  /*状态*/
    struct jincheng *next;                          /*下一进程*/
   }PCB;
//--------------------------------------------------------------------
void jiaohuan_fun(PCB P[MAXP],int i,int j)          /*交换*/
    {
     PCB a;
     a=P[i];P[i]=P[j];P[j]=a;     
    }
//---------------------------------------------------------------------
int input_func(PCB P[MAXP])                         /*输入函数*/
     {
       int i,j,n;
       cout<<"please input the process number:";    /*进程数*/
       cin>>n;
       cout<<"please input the message:"<<endl;     /*进程信息*/
       cout<<"Name Arrivetime Servetime Grade"<<endl;
       for(i=0;i<n;i++)
            {
             cin>>P[i].name;
             cin>>P[i].arrive;
             cin>>P[i].serve;
             cin>>P[i].grade;
             P[i].condition='W';
             P[i].next=NULL;
            }
       for(i=0;i<n-1;i++)                        /*按时间先后排序*/
         for(j=i+1;j<n;j++)
              if(P[i].arrive>P[j].arrive)                  
                jiaohuan_fun(P,i,j);              
       for(i=0;i<n-1;i++)                   /*同时到达按短作业优先*/
         for(j=i+1;j<n;j++)
              if(P[i].arrive==P[j].arrive&&P[i].serve>P[j].serve)                  
                jiaohuan_fun(P,i,j);               
       return n;
     }
//--------------------------------------------------------------------------