• Name: Mattia Laudenzi
  • Matricola: ldnmtt84r28h501o
  • Email: scrivimi84@libero.it

###################################################### #include <stdio.h>
#include <stdlib.h>

struct lista {
char *info;
struct lista *next;
};

typedef struct lista List;
typedef List* HashTable;


char *stringa();
HashTable crea (char *stringa);int find (lista *tabella, int dim, char *chiave);
void delete (lista *tabella, int dim, char *chiave);
void insert (lista *tabella, int dim, char *chiave);
int potenza(int esp, int dim);
int hash(char *word,int dim);

int main(){
List *tabella;



}







int find (lista *tabella, int dim, char *chiave){
lista *testa;
lista *appoggio;
int a;
a=hash(chiave);
appoggio=tabella[a];
if (tabella[a] == NULL) return -1;
else {
while (appoggio = NULL){
if (strcmp(appoggio->info,word))
return 1;
else appoggio=appoggio->next;
}return 0;

}
}

void insert (lista *tabella, int dim, char *chiave){
lista *testa; lista *appoggio;
lista *punta;
punta=testa;
appoggio=testa;
int a,b;
a=find(word);
if (a=-1){
b=hash(word,dim);
tabella[b]=crea(word);
}
if (a=0) {
punta=crea(word);
punta->next=testa;
tabella[b]=punta;}
}

void delete (lista *tabella, int dim, char *chiave){
lista *testa;
lista *appoggio;
lista *punta;
appoggio=tabella[a];
punta=appoggio;
if (strcmp(tabella[a]->info,word) == 0){
punta=tabella[a]->next;
free(appoggio);
tabella[a]=punta;
}
else {
while (appoggio = NULL){
if (strcmp(appoggio->info,word) == 0)
punta=appoggio->next;
free(appoggio);
else {
punta=appoggio;
appoggio=appoggio->next;
}return 0;
}
}












int hash(char *word,int dim){
int i,c,ritorno;
ritorno=0;
for (i=0;i<dim;i++){
ritorno+=(word[i]%dim)*potenza(i,dim);
ritorno=ritorno%dim;
}return ritorno;
}
int potenza(int esp,int dim){
int i,c;
int risultato;
risultato=1;
if (esp==0) return 1;
if (esp==1) return 256;
else for (i=0;i<=esp-1;i++){
risultato=(risultato%dim)*(256%dim);
}
risultato=risultato%dim;
return risultato;
}

lista *crea (char *stringa){
lista *elemento;
elemento=(lista*)malloc(sizeof(lista));
elemento->info=stringa;
elemento->next=NULL;
return elemento;
}

char *stringa(){
int i,c;
char *parola;
i=0;
parola=(char*)malloc(sizeof(char)*128);
while((c=getchar())!='\n'){
parola[i]=c;
i++;
}parola[i]='\0';
return parola;
}







/*lista *testa;
lista *appoggio;
testa=(lista*)malloc(sizeof(lista));
testa->next=(lista*)malloc(sizeof(lista)); appoggio=testa; appoggio=appoggio->next appoggio->next=(lista*)malloc(sizeof(lista)); appoggio=appoggio->next; appoggio->next=NULL; testa->info=(char*)malloc(sizeof(char)*128); testa->info[0]='c'; testa->info[1]='\0';*/

#######################################################

Edit | Attach | Watch | Print version | History: r7 < r6 < r5 < r4 < r3 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r7 - 2004-05-11 - MattiaLaudenzi






 
Questo sito usa cookies, usandolo ne accettate la presenza. (CookiePolicy)
Torna al Dipartimento di Informatica
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2008-2024 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback