static Scanner in = new Scanner(System.in);
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
int number = 5;
String [] jinchengnumber = new String [number];
for (int i = 0; i < number; i++) {
jinchengnumber[i] = "进程"+(i+1);
}
int [] jinrushijian = new int[number];
int [] yunxingshijian = new int [number];
System.out.println("请输入进程进入时间,且请大于1");
for(int i=0;i<number;i++)
{
jinrushijian[i] = in.nextInt();
}
System.out.println("请输入工作时间");
for(int i = 0;i<number;i++)
{
yunxingshijian[i]= in.nextInt();
}
for(int i =1;i<=4;i++)
{
System.out.println("请输入模式选择 1 为先来先服务 2为短进程优先 3为优先级算法");
int select= in.nextInt();
if(select == 1)
{
fristinfiristout(jinrushijian,jinchengnumber);
}
else if(select == 2)
{
short1(jinrushijian, yunxingshijian, jinchengnumber);
}
else {
youxianji(jinrushijian,jinchengnumber);
}
}
}
public static void fristinfiristout (int [] intime, String []jinchengnumber)
{
for (int i = 1; i < jinchengnumber.length; i++)
{
if (intime[i - 1] > intime[i])
{
String temp2 = jinchengnumber[i];
int temp = intime[i];
int j = i;
while (j > 0 && intime[j - 1] > temp)
{
jinchengnumber[j]=jinchengnumber[j-1];
intime[j] = intime[j-1];
j--;
}
intime[j] = temp;
jinchengnumber[j]=temp2;
}
}
for(int i =0;i<jinchengnumber.length;i++)
{
System.out.println(jinchengnumber[i]);
}
}
public static void short1(int[]intime,int[]worktime,String[]jinchengnumber)
{
int first =intime[0];
String firString = jinchengnumber[0];
for(int i=0;i<jinchengnumber.length;i++)
{
if(first>intime[i])
{
first = intime[i];
firString = jinchengnumber[i];
}
}
System.out.println("进程顺序为");
System.out.println(firString);
paixu(first,intime,worktime,jinchengnumber);
}
public static void youxianji(int []intime,String [] jinchengnumber)
{
int[]youxian = new int[5];
System.out.println("请输入优先级");
for(int i =0;i<5;i++)
{
youxian[i] = in.nextInt();
}
int frist =intime[0];
String fristString = jinchengnumber[0];
for(int i=0;i<5;i++)
{
if(frist>intime[i])
{
frist = intime[i];
fristString = jinchengnumber[i];
}
}
System.out.println("进程顺序为");
System.out.println(fristString);
paixu(frist,intime,youxian,jinchengnumber);
}
public static void paixu(int first,int[]intime,int[]thing,String[]jinchengnumber)
{
int [] newthing = new int[thing.length];
String [] newjinchengnumber =new String[jinchengnumber.length];
for(int i =0;i<intime.length;i++)
{
if(first !=intime[i])
{
newthing[i]=thing[i];
newjinchengnumber[i]=jinchengnumber[i];
}
}
String[]b = new String[newthing.length];
for(int i=0;i<newthing.length;i++)
{
int min=-1;
String min1="";
int wei=-1;
for(int j=0;j<newthing.length;j++)
{
if(newthing[j]!=-1)
{
min =newthing[j];
min1=newjinchengnumber[j];
wei=j;
break;
}
}
for(int p=0;p<newthing.length;p++)
{
if(newthing[p]!=-1&&newthing[p]<min)
{
min=newthing[p];
min1=newjinchengnumber[p];
wei=p;
}
}
b[i]=min1;
newthing[wei]=-1;
}
for(int i=1;i<newthing.length;i++)
{
System.out.println(b[i]);
}
}