Created
March 18, 2019 11:24
-
-
Save simondegheselle/4196ad31aec38feb3e39a8212da1c472 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// Created by simon on 17/03/19. | |
// | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include "insertion_sort.h" | |
#include <cmath> | |
using namespace std; | |
// segmentation fault, maar normaal is dit wel juist | |
void bucket_sort(vector<double> &v, int n) { | |
vector<vector<double>> b(n); | |
for (int i = 0; i < v.size(); i++) { | |
double firstDigit = v[i] * 10; | |
int bi = int(std::floor(firstDigit)); | |
b[bi].push_back(move(v[i])); | |
} | |
for(int i = 0; i < b.size(); i++) { | |
insertion_sort(b[i]); | |
} | |
int in =0; | |
for(int i = 0; i < b.size(); i++){ | |
for(int j = 0; j < b[i].size(); j++) { | |
v[in++] = b[i][j]; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment