/* Ejercicio 1 Tabla de dispersión Implemente una tabla de dispersión que puede contener hasta n enteros resolviendo los conflictos mediante listas simplemente enlazadas. Se debe poder insertar, remover y buscar elementos. El tiempo de ejecución de las inserciones debe ser O(1) en peor caso. */ #include struct nodoTDA{ int dato; nodoTDA *sig; } //El arreglo contiene punteros a los nodos struct tablaTDA{ int tamano; nodoTDA ** arreglo; } typedef tablaTDA* TDA; //Crear una tabla vacia de tamano n TDA CrearTDA(int n); //Inserta un elemento x en la tabla t void insertarTDA(int x, TDA &t); //Remueve un elemento x en la tabla t void removerTDA(int x, TDA &t); //Devuelve true si el elemento pertenece a la tabla t bool perteneceTDA(int x, TDA t); TDA CrearTDA(int n){ TDA nuevo = new tablaTDA; nuevo->tamano = n; nuevo->arreglo = new nodoTDA *[n]; for (int i=0;iarreglo[i]=NULL; } return nuevo; } void insertarTDA(int x, TDA &t){ //h es la funcion hash int indice = h(x) % t->tamano; nodoTDA * nuevo= new nodoTDA; nuevo->dato=x; nuevo->sig=t->arreglo[indice]; t->arreglo[indice]=nuevo; } void removerTDA(int x, TDA &t){ //h es la funcion hash int indice = h(x) % t->tamano; TDA aux=t->arreglo[indice]; while(aux != NULL && aux->dato == x){ t->arreglo[indice]=aux->sig; delete aux; aux=t->arreglo[indice]; } if (aux!=NULL){ while (aux->sig != NULL){ if (aux->sig->dato==x){ tablaTDA* aborrar= aux->sig; aux->sig=aux->sig->sig; delete aborrar; }else{ aux=aux->sig; } } } } bool perteneceTDA(int x, TDA t){ //h es la funcion hash int indice = h(x) % t->tamano; TDA aux=t->arreglo[indice]; while(aux != NULL && aux->dato != x){ aux=aux->sig; } return (aux!=NULL); } int main() { printf("Hello World"); return 0; }