fifo planning algorithm

1

I need to do the planning algorithm fifo , I'm doing it in Java but I'm stuck in the part of the processes to be organized, I have two Array one with the arrival time and the other with the time of rafagaCpu or service time, but when organizing the arrival time with a Sort I do not know how to make the Array rafagaCpu accommodate the new order of arrival time to be more explicit I will show it like this.

1. P1 5 6
2. P2 2 4
3. P3 0 3
4. P4 3 7

Where the first column is the processes, the second, time of arrival and the third is the Rafaga de cpu.

When I apply Sort the order changes only for the second column

1. P1 0 6
2. P2 2 4
3. P3 3 3
4. P4 5 7

I need the third one to do it too but I do not know how

 int tiempoLlegada[] = new int[numeroProcesos];
    int rafagaCpu[] = new int[numeroProcesos];

    for (int i = 0; i < numeroProcesos; i++) {
        tiempoLlegada[i] = Integer.parseInt(JOptionPane.showInputDialog(null,"Tiempo de llegada del proceso "+(i+1)));

        for (int j=0;i<numeroProcesos;j++){
            rafagaCpu[i]=Integer.parseInt(JOptionPane.showInputDialog(null,"Rafaga de Cpu del proceso "+(i+1)));
        }
    }
    Arrays.sort(tiempoLlegada);
    
asked by Felipe Peña 06.05.2017 в 06:52
source

1 answer

0

One solution would be to use a classic method Bubble , you could order the two arrangements in parallel, we order the array tiempoLlegada if the order of this is modified, we also modify the order of the elements of rafagaCpu . (detailed explanation on the link)

int[] tiempoLlegada = new int[]{ 16 , 4 , 18 ,12 ,1,6};
int[] rafagaCpu = new int[]{ 6 , 14 , 8 ,2,11 ,66}; 
int tmp = 0 ;
for (int j = 1; j < tiempoLlegada.length; j++) {
   for (int i = 0; i < tiempoLlegada.length-1; i++) {
       if(tiempoLlegada[i]>tiempoLlegada[i+1]){
          tmp = tiempoLlegada[i];
          tiempoLlegada[i] = tiempoLlegada[i+1];
          tiempoLlegada[i+1]= tmp;
          tmp = rafagaCpu[i];
          rafagaCpu[i] = rafagaCpu[i+1];
          rafagaCpu[i+1]= tmp;
       }
    }
}
System.out.println(Arrays.toString(tiempoLlegada));
System.out.println(Arrays.toString(rafagaCpu));

Exit

[1, 4, 6, 12, 16, 18]
[11, 14, 66, 2, 6, 8]
  

Keep in mind that with this method, within if you can modify    Arrays of any data type, but you must create the variable tmp   according to the type of Array .

    
answered by 06.05.2017 / 07:30
source