-
-
Save AgtLucas/56f84aba515afe2dce26 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class FirstFit { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
System.out.println("Entre com o número de processos:"); | |
int p = in.nextInt(); | |
System.out.println("Entre com o número de blocos de memória:"); | |
int m = in.nextInt(); | |
int parr[] = new int[p], | |
marr[] = new int[m]; | |
for (int i = 0; i < p; i++) { | |
System.out.println("TAMANHO PROCESSO (" + (i + 1) + ") :"); | |
parr[i] = in.nextInt(); | |
} | |
for (int i = 0; i < m; i++) { | |
System.out.println("TAMANHO MEMORIA [" + (i + 1) + "] :"); | |
marr[i] = in.nextInt(); | |
} | |
int j, i; | |
for (i = 0; i < p; i++) { | |
for (j = 0; j < m; j++) { | |
if(marr[j] >= parr[i]) { | |
marr[j] -= parr[i]; | |
System.out.println("Alocado processo " + (i+1) + " para memoria " + (j+1) + " tamanho que permaneceu depois de alocar " + marr[j]); | |
break; | |
} | |
} | |
if(j == m) { | |
System.out.println("Não há mais memória disponivel"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment