Advertisement
Guest User

Kumanovski dijalekt

a guest
Aug 28th, 2014
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.60 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #define MAX 1000
  6. #define     MEMCHECK(x) if(x==NULL) { printf("Nema memorija!\n"); exit(-1); }
  7.  
  8. typedef char * key_struct;
  9. typedef char * value_struct;
  10.  
  11. typedef struct hashmap_element
  12. {
  13.     key_struct key;                      // kluc
  14.     value_struct value;                  // vrednost
  15. }hashmap_node;                 // Definiranje element vo hash mapa
  16.  
  17. typedef struct element
  18. {
  19.     hashmap_node info;
  20.     struct element *link;
  21. } h_node;                        // Definiranje na element vo linearna lista (koficka) vo hash mapa
  22.  
  23. typedef h_node * h_nodep;
  24.  
  25. typedef struct cbht
  26. {
  27.     int size;
  28.     h_node ** buckets;           // niza od koficki (linearni listi)
  29. }hashmap;                      // Definiranje na hash mapa
  30.  
  31. void make_hash_map(hashmap *tptr, int n)  // inicijalizacija na hash mapa
  32. {
  33.     int i;
  34.     tptr->buckets=(h_node **) calloc(n, sizeof(h_node *));
  35.     // alokacija na memorija za nizata od koficki
  36.     tptr->size=n;
  37.     //for(i=0;i<tptr->size;i++)
  38.        // tptr->buckets[i]=NULL;
  39. }
  40.  
  41. int hashCode(key_struct key)
  42. {
  43.    //DEFINIRAJTE SVOJA HASH FUNKCIJA
  44. }
  45.  
  46. int hash(key_struct key, hashmap *tptr)
  47. { // funkcija koja presmetuva hash
  48.    return hashCode(key)%(tptr->size);
  49.  
  50. }
  51.  
  52.  h_node * search(key_struct targetKey, hashmap *tptr)
  53.  // funkcija za prebaruvanje vo hash
  54.  {
  55.     int h;
  56.     h_node *p;
  57.     h=hash(targetKey, tptr);
  58.     for(p=tptr->buckets[h]; p!=NULL; p=p->link)
  59.     {
  60.         if (!strcmp((p->info).key, targetKey))
  61.            return p;
  62.     }
  63.     return NULL;
  64. }
  65.  
  66. void insert(key_struct key, value_struct val, hashmap *tptr)
  67. // funkcija za vnesuvanje vo hash
  68. {
  69.     h_node *tmp;
  70.     h_node *p;
  71.     int h;
  72.  
  73.     h=hash(key, tptr);
  74.     p=(h_node *) malloc(sizeof(h_node));  // alokacija za noviot jazel
  75.     (p->info).value=val;
  76.     (p->info).key=key;
  77.  
  78.     for(tmp=tptr->buckets[h]; tmp!=NULL; tmp=tmp->link)
  79.     {// ako veke postoi takov zapis
  80.         if (!strcmp((tmp->info).key, key))
  81.         {
  82.             (tmp->info).value=val;   // se zamenuva so novata vrednost
  83.             return;
  84.         }
  85.     }
  86.  
  87.     // se vnesuva noviot jazel na pocetokot na kofickata h
  88.     p->link=tptr->buckets[h];
  89.     tptr->buckets[h]=p;
  90. }
  91.  
  92. void delete(key_struct key, hashmap *tptr)
  93. // funkcija za brisenje na onie jazli so ist kluc kako dadeniot
  94. {
  95.    h_node *p, *last;
  96.    int h;
  97.  
  98.    h=hash(key,tptr);
  99.    for (p=tptr->buckets[h]; p!=NULL; p=p->link) {
  100.      if (!strcmp((p->info).key, key))
  101.        break;
  102.    }
  103.    if (p==NULL) return;   // ako nema takvi jazli za brisenje
  104.  
  105.    if(p==tptr->buckets[h])   // ako najdeniot e na pocetok na koficka za brisenje
  106.      tptr->buckets[h]=p->link;
  107.    else
  108.    {
  109.      // naoganje na prethodnikot na jazelot sto treba da se izbrise
  110.      for (last=tptr->buckets[h];(last!=NULL)&&(last->link!=NULL);last=last->link) {
  111.        if (last->link==p)
  112.          break;
  113.      }
  114.      last->link=p->link;
  115.    }
  116.  
  117.    free(p);                  // brisenje na jazel
  118. }
  119.  
  120.  
  121.  
  122. int main()
  123. {
  124.     hashmap *hashTabela=(hashmap *)malloc(sizeof(hashmap));
  125.     int N,i;
  126.     scanf("%d",&N);
  127.     //sami odredete ja goleminata na hashTabelata
  128.     make_hash_map(hashTabela,????);
  129.  
  130.     char zborKu[100][30],zborMk[100][30];
  131.     for(i=0; i<N; i++)
  132.     {
  133.         scanf("%s %s",zborKu[i],zborMk[i]);
  134.     }
  135.  
  136.  
  137.     char tekst[1000];
  138.     char c ;
  139.     scanf("%c",&c);
  140.     i=0;
  141.     while(1)
  142.     {
  143.         tekst[i]=c;
  144.         scanf("%c",&c);
  145.         i++;
  146.         if(c=='\n')
  147.             break;
  148.     }
  149.  
  150.     tekst[i]='\0';
  151.    
  152.     //vasiot kod tuka
  153.    
  154.    
  155.     return 0;
  156. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement