Enviado em 04/06/2021 - 14:45h
Boa tarde pessoal, tudo bem ?#include <stdio.h> #include <stdlib.h> #include <string.h> struct item { int x; char str[4]; }; struct hashtable { int flag; int tamanho; struct item *item; }; struct hashtable *hashtable; //prototipos ------------------------------------------ void inicia_v(int tam_hash); int hashcode(int x, int tam_hash); //void inserir(char *alfanum, int tam_hash); //main ------------------------------------------ int main() { //int tam_hash = 5; inicia_v(5); return 0; } //funções ------------------------------------------ void inicia_v(int tam_hash) { int i; for ( i = 0; i < tam_hash; i++) { hashtable[i].flag = 0; hashtable[i].tamanho = 0; hashtable[i].item = NULL; } } int hashcode(int x, int tam_hash) { return (x) % (tam_hash); }
Enviado em 04/06/2021 - 20:25h
for (i = 0; i < tamhash; i++) { thash[i] = -1; } }
Enviado em 04/06/2021 - 16:02h
A variável hastable é um ponteiro que não aponta para nenhum conteúdo de memória, e fora que, nem foi alocado memoria pra ela.Enviado em 04/06/2021 - 17:48h
#include <stdio.h> #include <stdlib.h> #include <string.h> int hashcode(int x, int tamhash) { return (x % tamhash); } int inserir(int *thash, int key, int tamhash) { int i, index, hashpos; //int flag = 0; hashpos = hashcode(key, tamhash); for (i = 0; i < tamhash; i++) { thash[i] = -1; } for (i = 0; i < tamhash; i++) { index = (hashpos + i*i) % tamhash; if(thash[index] == -1) { thash[index] = key; break; } } if(i == tamhash) { printf("\nElemento não pode ser inserido.\n"); return 1; } return 0; } void display_table(int *thash, int tamhash) { int i; printf("\nHash Fechado - Tentativa Quadratica\n"); for(i = 0; i < tamhash; i++) { printf("\nv[%d] .... %d", i, thash[i]); } printf("\n"); } int main() { int tam_hash = 5; int *tablehash; tablehash = (int *)malloc(sizeof(int) * tam_hash); inserir(tablehash, 2, 5); inserir(tablehash, 12, 5); inserir(tablehash, 10, 5); inserir(tablehash, 50, 5); display_table(tablehash, 5); return 0; }
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Solução rápida para o problema do Network Manager conectar mas não navegar
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
Ajuda Pra Melhoria do NFTABLES. (5)
Sunshine e Moonlight Linux (0)