Facebook
From Morose Lizard, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 108
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int rozmiartab = 32;
  6.  
  7. struct Node{
  8.         char dane;
  9.         Node *next;
  10.         Node *prev;
  11. };
  12.  
  13. int tab[rozmiartab];
  14.  
  15. void emptytab(){
  16.  
  17.     for(int i = 0; i<rozmiartab; i++){
  18.         tab[i] = 0;
  19.     }
  20.  
  21. };
  22.  
  23. int has(char wartosc){
  24.     int q = wartosc.lenght();
  25.     int N = rozmiartab;
  26.     int h = 0;
  27.     for(int i = 0; i < q; i++){
  28.         h += wartosc[i] * (31^(q-(i+1)));
  29.     }
  30.     return h %= N;
  31. };
  32.  
  33. void insert(char dane){
  34.     struct Node* newNode = new Node;
  35.     newNode -> next = NULL;
  36.  
  37.     int index = has(dane);
  38.  
  39.     if(tab[index]==0){
  40.         tab[index] = newNode;
  41.         //kolizja
  42.     }else{
  43.         struct Node* temp = tab[index];
  44.         while(temp->next){
  45.             temp = temp -> next;
  46.         }
  47.         temp -> next = newNode;
  48.     }
  49. }
  50.  
  51. void print(){
  52.     for(int i = 0; i < rozmiartab; i++){
  53.         cout<<(int)i<<". --- "<< tab[i]<<endl;
  54.     }
  55. };
  56.  
  57.  
  58.  
  59.  
  60. int main() {
  61.  
  62.     insert('adam');
  63.  
  64.     print();
  65.  
  66.     return 0;
  67. }
  68.