Você está na página 1de 6

Nome: Bruno Lopes da Cunha - RA: A3684D-1

Nome: Leonardo
- RA:

Algoritmo para Falta de Pginas


<html>
<head>
<title>
Algoritmos de Falta de Pginas
</title>
<!-- Script -->
<script type="text/javascript">
//--------------------------------------------------------------//Funo que mostra as colunas
function showDinamicColumns(v1,v2,v3,v4,v5){
var dados = "";
for (i = 0; i < v1.length; i++){
dados += "<tr>" +
"<td align='center'>" +
v1[i] +
"</td>" +
"<td align='center'>" +
v2[i] +
"</td>" +
"<td align='center'>" +
v3[i] +
"</td>" +
"<td align='center'>" +
v4[i] +
"</td>" +
"<td align='center'>" +
v5[i] +
"</td>" +
"</tr>";
}
//Adiciona as linhas na tela
colunasDinamicas.innerHTML = dados;
}

//--------------------------------------------------------------//Funo que salva os novos valors nos vetores


function addVetor(v1,v2,v3,v4,v5){
//Verifica se os campos esto validados
if (((document.getElementById('textPagina').value != "" ) &&
(!isNaN(document.getElementById('textPagina').value))) &&

((document.getElementById('textCarregado').value !=
"" ) && (!isNaN(document.getElementById('textCarregado').value))) &&
((document.getElementById('textUltima').value != "" )
&& (!isNaN(document.getElementById('textUltima').value))) &&
((document.getElementById('textR').value != "" ) &&
(!isNaN(document.getElementById('textR').value))) &&
((document.getElementById('textM').value != "" ) &&
(!isNaN(document.getElementById('textM').value))))
{
v1.push(parseInt(document.getElementById('textPagina').value));
v2.push(parseInt(document.getElementById('textCarregado').value));
v3.push(parseInt(document.getElementById('textUltima').value));
v4.push(parseInt(document.getElementById('textR').value));
v5.push(parseInt(document.getElementById('textM').value));

//Cham funo que muda as tabelas


showDinamicColumns(v1,v2,v3,v4,v5);
//Limpa todos os campos
document.getElementById('textPagina').value = "";
document.getElementById('textCarregado').value = "";
document.getElementById('textUltima').value = "";
document.getElementById('textR').value = "";
document.getElementById('textM').value = "";
}
else {
alert('Por favor, insira nmeros em todos os campos!');
}
}
//--------------------------------------------------------------//Algoritmos
//Relgio
function algRelogio(v1,v2,v3,v4,v5){
console.log(v1,v2,v3,v4,v5);
}
//NRU
function algNRU(v1,v2,v3,v4,v5){
console.log(v1,v2,v3,v4,v5);
}
//FIFO
function algFIFO(v1,v2,v3,v4,v5){
if (!isNaN(v2[0])){
var menor = v2[0];

var position = 0;
for (i = 0; i < v2.length; i++){
if (v2[i] < menor){
menor = v2[i];
position = i;
}
}
v1.splice(position, 1);
v2.splice(position, 1);
v3.splice(position, 1);
v4.splice(position, 1);
v5.splice(position, 1);
//Cham funo que muda as tabelas
showDinamicColumns(v1,v2,v3,v4,v5);
}
else {
alert("A tabela est vazia!");
}
}
//Segunda Chance
function algSegChance(v1,v2,v3,v4,v5){
console.log(v1,v2,v3,v4,v5);
}
//LRU
function algLRU(v1,v2,v3,v4,v5){
if (!isNaN(v3[0])){
var menor = v3[0];
var position = 0;
for (i = 0; i < v3.length; i++){
if (v3[i] < menor){
menor = v3[i];
position = i;
}
}
v1.splice(position, 1);
v2.splice(position, 1);
v3.splice(position, 1);
v4.splice(position, 1);
v5.splice(position, 1);
//Cham funo que muda as tabelas
showDinamicColumns(v1,v2,v3,v4,v5);
}
else {
alert("A tabela est vazia!");
}
}
//--------------------------------------------------------------//Vetores com os dados

var pagina = [];


var carregado = [];
var ultima = [];
var r = [];
var m = [];
//--------------------------------------------------------------//Inicio da Pgina
document.write(
"<h2>" +
"Algoritmos de Falta de Pginas" +
"</h2>"
);
document.write(
"<br />" +
"<br />"
);
//Cria a tabela
document.write(
"<div id='teste'>" +
"<table border='1'>" +
"<tr>" +
"<th>" +
"Pgina" +
"</th>" +
"<th>" +
"Carregando" +
"</th>" +
"<th>" +
"ltima Refeferncia" +
"</th>" +
"<th>" +
"R" +
"</th>" +
"<th>" +
"M" +
"</th>" +
"</tr>" +
"<tbody id='colunasDinamicas'>" +
"</tbody>" +
"<tr>" +
"<td>" +
"<input type='text'
id='textPagina' name='textPagina' />" +
"</td>" +
"<td>" +
"<input type='text'
id='textCarregado' name='textCarregado' />" +
"</td>" +
"<td>" +

"<input type='text'
id='textUltima' name='textUltima' />" +
"</td>" +
"<td>" +
"<input type='text' id='textR'
name='textR' />" +
"</td>" +
"<td>" +
"<input type='text' id='textM'
name='textM' />" +
"</td>" +
"</tr>" +
"</table>" +
"</div>"
);
document.write(
"<br />"
);
//Boto para atualizar a tabela
document.write(
"<input type='button' id='buttonAtualizar'
name='buttonAtualizar' onClick='addVetor(pagina,carregado,ultima,r,m)' value='Atualizar' />"
);
document.write(
"<br />" +
"<br />"
);
//--------------------------------------------------------------//Algoritmos
document.write(
"<input type='button' id='buttonRelogio' name='buttonRelogio'
value='Relogio' onClick='algRelogio(pagina,carregado,ultima,r,m)' />"
);
document.write(
"<input type='button' id='buttonRelogio' name='buttonRelogio'
value='NRU' onClick='algNRU(pagina,carregado,ultima,r,m)' />"
);
document.write(
"<input type='button' id='buttonRelogio' name='buttonRelogio'
value='FIFO' onClick='algFIFO(pagina,carregado,ultima,r,m)' />"
);
document.write(
"<input type='button' id='buttonRelogio' name='buttonRelogio'
value='Segunda Chance' onClick='algSegChance(pagina,carregado,ultima,r,m)' />"
);
document.write(
"<input type='button' id='buttonRelogio' name='buttonRelogio'
value='LRU' onClick='algLRU(pagina,carregado,ultima,r,m)' />"
);

</script>
</head>
<body>
</body>
</html>

Você também pode gostar