Advertisement
Guest User

Ejercicio que sigue

a guest
Oct 16th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n = 29;
  8. vector<int*> buckets(n, nullptr);
  9.  
  10. auto hp = [](int k) { return k % 19; };
  11. int c1 = 0;
  12. int c2 = 1;
  13. auto h = [=](int k, int i) {
  14. return (hp(k) + c1*i + c2*i*i) % n;
  15. };
  16.  
  17. vector<int> nums={6, 34, 67, 92, 96, 8, 53, 5, 3, 2};
  18. for (auto k : nums) {
  19. for (int i = 0; i < n; ++i) {
  20. auto index = h(k, i);
  21. cout << index << " ";
  22. if (buckets[index] == nullptr) {
  23. buckets[index] = new int;
  24. (*buckets[index]) = k;
  25. break;
  26. }
  27. }
  28. cout << endl;
  29. }
  30.  
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement