Last active
March 18, 2019 21:08
-
-
Save simondegheselle/e8f95476e2d9c0a774e86a071529cd93 to your computer and use it in GitHub Desktop.
This file contains 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(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