SHARE
TWEET

Untitled

a guest Mar 23rd, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //
  2. // Created by simon on 17/03/19.
  3. //
  4.  
  5. #include <vector>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include "insertion_sort.h"
  9. #include <cmath>
  10.  
  11. using namespace std;
  12.  
  13. // segmentation fault, maar normaal is dit wel juist
  14. void bucket_sort(vector<double> &v, int n) {
  15.     vector<vector<double>> b(n);
  16.    
  17.     for (int i = 0; i < v.size(); i++) {
  18.         double firstDigit = v[i] * 10;
  19.         int bi = int(std::floor(firstDigit));
  20.         b[bi].push_back(move(v[i]));
  21.     }
  22.  
  23.     for(int i = 0; i < b.size(); i++) {
  24.         insertion_sort(b[i]);
  25.     }
  26.  
  27.     int in =0;
  28.     for(int i = 0; i < b.size(); i++){
  29.         for(int j = 0; j < b[i].size(); j++) {
  30.             v[in++] = b[i][j];
  31.         }
  32.     }
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top