Advertisement
Guest User

aicia

a guest
Jan 16th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include "Header.h"
  2. void HashMap::init()
  3. {
  4.     vect = new Node*[MAX_DIM];
  5.     for (int i = 0; i < MAX_DIM; i++)
  6.     {
  7.         vect[i] = NULL;
  8.     }
  9. }
  10. int HashMap::HashFunction(string _key)
  11. {
  12.     int index;
  13.     int sum = sizeof(_key);
  14.     index = sum%MAX_DIM;
  15.     return index;
  16. }
  17.  
  18. void HashMap::afisare()
  19. {
  20.     for (int i = 0; i < MAX_DIM; i++)
  21.     {
  22.         if (&vect[i] != NULL)
  23.         {
  24.             cout << "Nume produs: " << vect[i]->name << endl << "Pret: " << vect[i]->pret << endl;
  25.         }
  26.     }
  27. }
  28.  
  29. void HashMap::insert(string _data, int _pret)
  30. {
  31.     int index = this->HashFunction(_data);
  32.     auto name = new char[sizeof(_data)];
  33. //de aici incepe sa crape cred
  34.     strcpy_s(vect[index]->name,sizeof(name),name);
  35.     vect[index]->pret = _pret;
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement