Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <stdlib.h>
- #include <string.h>
- #define MAX 1000
- #define MEMCHECK(x) if(x==NULL) { printf("Nema memorija!\n"); exit(-1); }
- typedef char * key_struct;
- typedef char * value_struct;
- typedef struct hashmap_element
- {
- key_struct key; // kluc
- value_struct value; // vrednost
- }hashmap_node; // Definiranje element vo hash mapa
- typedef struct element
- {
- hashmap_node info;
- struct element *link;
- } h_node; // Definiranje na element vo linearna lista (koficka) vo hash mapa
- typedef h_node * h_nodep;
- typedef struct cbht
- {
- int size;
- h_node ** buckets; // niza od koficki (linearni listi)
- }hashmap; // Definiranje na hash mapa
- void make_hash_map(hashmap *tptr, int n) // inicijalizacija na hash mapa
- {
- int i;
- tptr->buckets=(h_node **) calloc(n, sizeof(h_node *));
- // alokacija na memorija za nizata od koficki
- tptr->size=n;
- //for(i=0;i<tptr->size;i++)
- // tptr->buckets[i]=NULL;
- }
- int hashCode(key_struct key)
- {
- //DEFINIRAJTE SVOJA HASH FUNKCIJA
- }
- int hash(key_struct key, hashmap *tptr)
- { // funkcija koja presmetuva hash
- return hashCode(key)%(tptr->size);
- }
- h_node * search(key_struct targetKey, hashmap *tptr)
- // funkcija za prebaruvanje vo hash
- {
- int h;
- h_node *p;
- h=hash(targetKey, tptr);
- for(p=tptr->buckets[h]; p!=NULL; p=p->link)
- {
- if (!strcmp((p->info).key, targetKey))
- return p;
- }
- return NULL;
- }
- void insert(key_struct key, value_struct val, hashmap *tptr)
- // funkcija za vnesuvanje vo hash
- {
- h_node *tmp;
- h_node *p;
- int h;
- h=hash(key, tptr);
- p=(h_node *) malloc(sizeof(h_node)); // alokacija za noviot jazel
- (p->info).value=val;
- (p->info).key=key;
- for(tmp=tptr->buckets[h]; tmp!=NULL; tmp=tmp->link)
- {// ako veke postoi takov zapis
- if (!strcmp((tmp->info).key, key))
- {
- (tmp->info).value=val; // se zamenuva so novata vrednost
- return;
- }
- }
- // se vnesuva noviot jazel na pocetokot na kofickata h
- p->link=tptr->buckets[h];
- tptr->buckets[h]=p;
- }
- void delete(key_struct key, hashmap *tptr)
- // funkcija za brisenje na onie jazli so ist kluc kako dadeniot
- {
- h_node *p, *last;
- int h;
- h=hash(key,tptr);
- for (p=tptr->buckets[h]; p!=NULL; p=p->link) {
- if (!strcmp((p->info).key, key))
- break;
- }
- if (p==NULL) return; // ako nema takvi jazli za brisenje
- if(p==tptr->buckets[h]) // ako najdeniot e na pocetok na koficka za brisenje
- tptr->buckets[h]=p->link;
- else
- {
- // naoganje na prethodnikot na jazelot sto treba da se izbrise
- for (last=tptr->buckets[h];(last!=NULL)&&(last->link!=NULL);last=last->link) {
- if (last->link==p)
- break;
- }
- last->link=p->link;
- }
- free(p); // brisenje na jazel
- }
- int main()
- {
- hashmap *hashTabela=(hashmap *)malloc(sizeof(hashmap));
- int N,i;
- scanf("%d",&N);
- //sami odredete ja goleminata na hashTabelata
- make_hash_map(hashTabela,????);
- char zborKu[100][30],zborMk[100][30];
- for(i=0; i<N; i++)
- {
- scanf("%s %s",zborKu[i],zborMk[i]);
- }
- char tekst[1000];
- char c ;
- scanf("%c",&c);
- i=0;
- while(1)
- {
- tekst[i]=c;
- scanf("%c",&c);
- i++;
- if(c=='\n')
- break;
- }
- tekst[i]='\0';
- //vasiot kod tuka
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement