Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
htabprepa
//Title of this code //gcc 4.9.2 #include <stdio.h> #include<string.h> typedef struct Cell Cell; struct Cell{ char*key; Cell*next; }; int lookup(char*anahtar,Cell*list) { if(list==NULL)return 0; else if (!strcmp(anahtar,list->key)) return 1; else return lookup(anahtar,list->next); } int insert(char*anahtar,Cell**list){ if(*list==NULL){ *list=(Cell*)malloc(sizeof(Cell)); (*list)->key=(char*)malloc(sizeof(char)*strlen(anahtar)); (*list)->next=NULL; return 1; } else if (strcmp(anahtar,(*list)->key)) return insert(anahtar,&((*list)->next)); else return 0; } void print_list(Cell*list){ if(list!=NULL){ printf("%s",list->key); print_list(list->next); } } typedef struct Node Node; struct Node{ Cell*head; int value; }; typedef struct Hash Hashtab; struct Hash{ int size; Node*table; }; unsigned hash_function(char*anahtar,int size){ unsigned value=0; int i=0; value=(anahtar[i]+5*value)%size; return value ; } void initialize_hash(int size,Hashtab*tab){ int i; tab->table=(Node*)malloc(sizeof(Node)*size); tab->size=size; for(i=0;i<size;i++){ (tab->table+i)->value=0; (tab->table+i)->head=NULL; } } void insert_hash(char*anahtar,Hashtab*tab){ int index=hash_function(anahtar,tab->size); if(insert(anahtar,&((tab->table+index)->head))) (tab->table+index)->value++; } void print_hash(Hashtab*tab){ if(tab){ printf("Hash Table :\n"); int i; for(i=0;i<tab->size;i++){ printf("%5d: ( %2d )",i,(tab->table+i)->value); print_list((tab->table+i)->head); printf("\n"); } } else printf("Empty Hash Table "); } int main(void) { }
run
|
edit
|
history
|
help
0
Memory leak
B_14118_RestasSucesivas
tom grey wolf
Project 3 part 2 Book v1.1
1.3 Max threads
B_141202_PALINDROMO
Media de 3 numeros
time conversion1
Day 2 String Manipulation
150109_RecursividadPrimo