Ir para conteúdo
Fórum Script Brasil

douglasThome

Membros
  • Total de itens

    1
  • Registro em

  • Última visita

Sobre douglasThome

douglasThome's Achievements

0

Reputação

  1. douglasThome

    Tabela hash

    Olá! estou com algumas duvidas , escrevi um código de uma tabela hash ,mas estou com dificuldades de fazer ele compilar e estar testando ele. (codigo a baixo) const int TAM = 2000; using namespace std; struct Tcliente{ int codigo; string nome; }; template <int M> struct THashEA{ Tcliente *tabela[M]; int qtd; }; template <int M> void inicializaTHEA(THashEA<M> & th){ th.qtd = 0; for(int i= 0; i < M ; i++){ th.tabela= NULL; } } template <int M> int funcaoTransf (THashEA<M> &th , int chave){ return chave % M ; } template <int M> bool insereTHEA(THashEA<M> & th , Tcliente c){//criar cliente(OBS: Tcliente *c,cria) Tcliente *nov = new Tcliente; int code = nov->codigo; int hashe = funcaoTransf(th , code); if(th.qtd == 0){ th.tabela[hashe] = nov; th.qtd++; return true; } for(int i = hashe; i <M ; i++){//procura posição livre da posição da chave if(th.tabela == NULL){// verifica se a posição e nula para poder alocar th.tabela[hashe] = nov; th.qtd++; return true; } } return false; } template <int M> bool pesquisaTHEA(THashEA<M> & th , int codigo){ //procurar indice Hash(FT) //procurar a chave codigo = funcaoTransf(th , codigo); for(int i=codigo ; i < M ; i++){ if(th.tabela= codigo){ return true; } } return false; } int main(){ srand(time(NULL)); THashEA *tabhash<TAM>; Tcliente *novo = new Tcliente; novo->codigo = rand() %32000+1; insereTHEA(tab<TAM>,novo) } Primeiro queria saber se o codigo da estrutura da tabela contem erros ,e depois o motivo do qual eu não consigo criar na fução main() a tabela (THashEA *tabhash<TAM>;) Desde já agradeço a atenção.
×
×
  • Criar Novo...