Tabela hash

289 palavras 2 páginas
#include
#include
#include
#include

#define tam 7

int pesos[20]={2,3,5,8,13,21,34,55,89,144,3,4,6,9,14,22,35, 56,90,145} ;

struct item { char chave[20]; int reg; struct item *proximo;
};

struct item *hash[tam] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL};
//----------------------------------
void menu(); void ler(); void listar(); void insere(char chave[20],int reg); int pesquisa(char chave[20]); int h(char chave[20]);

//---------------------------------------------------------------

main(){ menu();
}

//---------------------------------------------------------------

void menu(){ int opcao, reg; char chave[20];

system("cls"); printf("\n 1 - Ler"); printf("\n 2 - Tabela Hash"); printf("\n 3 - Listar"); printf("\n 4 - Sair"); printf("\n Opcao: "); scanf("%d",&opcao); switch(opcao) { case 1: ler(); printf("\n Ordenação concluida com sucesso"); getch(); menu(); break;

case 2 : printf("\n Informe a chave de pesquisa: "); scanf("%s",&chave); reg = pesquisa(chave); if (reg == -1) printf("\n Chave de pesquisa não foi encontrada"); else printf("\n A Chave pertence ao registro %d",reg); getch(); menu(); break; case 3: listar(); getch(); // ver msg menu(); break; case 4: exit(0); default: printf("\n Opcao invalida"); getch(); menu();
} // swicth
} // menu

//---------------------------------------------------------------

void ler(){ char chave[20]; int i;

for(i=1;ichave,chave); aux->reg = reg; aux->proximo = NULL; if (hash[i]== NULL) hash[i] = aux; else { auxp=hash[i]; while(auxp->proximo != NULL) auxp = auxp->proximo; auxp->proximo = aux; } // else
} // insere

Relacionados

  • Tabelas HASH
    1019 palavras | 5 páginas
  • Tabela hash
    510 palavras | 3 páginas
  • Tabelas Hash
    1787 palavras | 8 páginas
  • Tabela Hash
    2579 palavras | 11 páginas
  • Tabelas Hash
    2134 palavras | 9 páginas
  • Tabela Hash
    1859 palavras | 8 páginas
  • Tabela hash
    14106 palavras | 57 páginas
  • PESQUISA TABELA HASH
    1659 palavras | 7 páginas
  • Exemplo tabela hash
    596 palavras | 3 páginas
  • Exercícios com tabela hash
    306 palavras | 2 páginas