Skip to content

Instantly share code, notes, and snippets.

@simondegheselle
Created March 18, 2019 15:46
Show Gist options
  • Save simondegheselle/a0fe6a63cb06bafa6e047ca2a9a9c876 to your computer and use it in GitHub Desktop.
Save simondegheselle/a0fe6a63cb06bafa6e047ca2a9a9c876 to your computer and use it in GitHub Desktop.
//
// 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[0].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