From 74a0c6b88c555d767c0dee17e0b48e5e9ef66d77 Mon Sep 17 00:00:00 2001 From: Felipe Domingos Date: Wed, 1 Dec 2021 10:20:22 -0300 Subject: [PATCH] =?UTF-8?q?identa=C3=A7=C3=A3o=20resolvida!?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/hashDiretoRehash/Hash.java | 52 +++++++------------ .../java/hashDiretoReserva/Hash.java | 48 +++++++---------- .../java/hashIndiretoLista/Hash.java | 19 ++++--- tps/fonte/Serie.java | 2 + 4 files changed, 50 insertions(+), 71 deletions(-) diff --git a/fonte/u09 Tabelas e dicionários/java/hashDiretoRehash/Hash.java b/fonte/u09 Tabelas e dicionários/java/hashDiretoRehash/Hash.java index c161b19..cd1cd28 100644 --- a/fonte/u09 Tabelas e dicionários/java/hashDiretoRehash/Hash.java +++ b/fonte/u09 Tabelas e dicionários/java/hashDiretoRehash/Hash.java @@ -1,76 +1,64 @@ -class Hash { + +public class Hash { int tabela[]; int m; - int NULO = -1; + final int NULO = -1; - public Hash (){ + public Hash() { this(13); } - public Hash (int m){ + public Hash(int m) { this.m = m; - this.tabela = new int [this.m]; - for(int i = 0; i < m; i++){ + this.tabela = new int[this.m]; + for (int i = 0; i < m; i++) { tabela[i] = NULO; } } - public int h(int elemento){ + public int h(int elemento) { return elemento % m; } - public int reh(int elemento){ + public int reh(int elemento) { return ++elemento % m; } - public boolean inserir (int elemento){ + public boolean inserir(int elemento) { boolean resp = false; - - if(elemento != NULO){ - + if (elemento != NULO) { int pos = h(elemento); - - if(tabela[pos] == NULO){ + if (tabela[pos] == NULO) { tabela[pos] = elemento; resp = true; - - } else{ - + } else { pos = reh(elemento); - - if(tabela[pos] == NULO){ + if (tabela[pos] == NULO) { tabela[pos] = elemento; resp = true; } } } - return resp; } - public boolean pesquisar (int elemento){ + public boolean pesquisar(int elemento) { boolean resp = false; - int pos = h(elemento); - - if(tabela[pos] == elemento){ + if (tabela[pos] == elemento) { resp = true; - - } else { + } else if (tabela[pos] != NULO) { pos = reh(elemento); - - if(tabela[pos] == elemento){ + if (tabela[pos] == elemento) { resp = true; } } return resp; } - boolean remover (int elemento){ + boolean remover(int elemento) { boolean resp = false; - - //... - + // ... return resp; } } diff --git a/fonte/u09 Tabelas e dicionários/java/hashDiretoReserva/Hash.java b/fonte/u09 Tabelas e dicionários/java/hashDiretoReserva/Hash.java index 9b86ef9..b976952 100644 --- a/fonte/u09 Tabelas e dicionários/java/hashDiretoReserva/Hash.java +++ b/fonte/u09 Tabelas e dicionários/java/hashDiretoReserva/Hash.java @@ -1,60 +1,52 @@ + public class Hash { int tabela[]; int m1, m2, m, reserva; - int NULO = -1; + final int NULO = -1; - public Hash (){ + public Hash() { this(13, 7); } - public Hash (int m1, int m2){ + public Hash(int m1, int m2) { this.m1 = m1; - this.m2 = m2; + this.m2 = m2; this.m = m1 + m2; - this.tabela = new int [this.m]; - for(int i = 0; i < m1; i++){ + this.tabela = new int[this.m]; + for (int i = 0; i < m1; i++) { tabela[i] = NULO; } reserva = 0; } - public int h(int elemento){ + public int h(int elemento) { return elemento % m1; } - public boolean inserir (int elemento){ + public boolean inserir(int elemento) { boolean resp = false; - - if(elemento != NULO){ - + if (elemento != NULO) { int pos = h(elemento); - - if(tabela[pos] == NULO){ + if (tabela[pos] == NULO) { tabela[pos] = elemento; resp = true; - - } else if (reserva < m2){ + } else if (reserva < m2) { tabela[m1 + reserva] = elemento; reserva++; resp = true; } } - return resp; } - - public boolean pesquisar (int elemento){ + public boolean pesquisar(int elemento) { boolean resp = false; - int pos = h(elemento); - - if(tabela[pos] == elemento){ + if (tabela[pos] == elemento) { resp = true; - - } else { - for(int i = 0; i < reserva; i++){ - if(tabela[m1 + i] == elemento){ + } else if (tabela[pos] != NULO) { + for (int i = 0; i < reserva; i++) { + if (tabela[m1 + i] == elemento) { resp = true; i = reserva; } @@ -63,11 +55,9 @@ public class Hash { return resp; } - boolean remover (int elemento){ + boolean remover(int elemento) { boolean resp = false; - - //... - + // ... return resp; } } diff --git a/fonte/u09 Tabelas e dicionários/java/hashIndiretoLista/Hash.java b/fonte/u09 Tabelas e dicionários/java/hashIndiretoLista/Hash.java index 9a7e161..d37bc3c 100644 --- a/fonte/u09 Tabelas e dicionários/java/hashIndiretoLista/Hash.java +++ b/fonte/u09 Tabelas e dicionários/java/hashIndiretoLista/Hash.java @@ -3,35 +3,35 @@ class HashIndiretoLista { int tamanho; final int NULO = -1; - public HashIndiretoLista (){ + public HashIndiretoLista() { this(7); } - public HashIndiretoLista (int tamanho){ + public HashIndiretoLista(int tamanho) { this.tamanho = tamanho; tabela = new Lista[tamanho]; - for(int i = 0; i < tamanho; i++){ + for (int i = 0; i < tamanho; i++) { tabela[i] = new Lista(); } } - public int h(int elemento){ + public int h(int elemento) { return elemento % tamanho; } - boolean pesquisar(int elemento){ + boolean pesquisar(int elemento) { int pos = h(elemento); return tabela[pos].pesquisar(elemento); } - public void inserirInicio (int elemento){ + public void inserirInicio(int elemento) { int pos = h(elemento); tabela[pos].inserirInicio(elemento); } -/* - void remover(int elemento){ + + public int remover(int elemento) { int resp = NULO; - if (pesquisar(elemento) == false){ + if (pesquisar(elemento) == false) { throw new Exception("Erro ao remover!"); } else { int pos = h(elemento); @@ -39,5 +39,4 @@ class HashIndiretoLista { } return resp; } -*/ } diff --git a/tps/fonte/Serie.java b/tps/fonte/Serie.java index 38a85d3..a0f48db 100644 --- a/tps/fonte/Serie.java +++ b/tps/fonte/Serie.java @@ -166,6 +166,7 @@ class Serie { //System.out.println(resp); return resp; } + //método para tratar o nome do arquivo e retornar o nome da série public String searchName(String fileName){ String resp = ""; @@ -178,6 +179,7 @@ class Serie { } return resp.substring(0, resp.length()-5); //retorno da substring resp retirando os 5 últimos caracteres relacionados à extensão do arquivo } + //método para leitura do arquivo .html e tratamento das linhas public void readClass(String fileName){ String line;