Skip to content

Commit

Permalink
Merge pull request #69 from heyimShivam/bucketShort
Browse files Browse the repository at this point in the history
Bucket Sort Algorithm Added issue::#67
  • Loading branch information
vaibhavpathak999 committed Oct 1, 2021
2 parents 3e2f903 + 3e656b4 commit 59869e6
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Sorting Algos/Quick Sort/Bucket Sort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

void bucketSort(float arr[], int n)
{


vector<float> b[n];


for (int i = 0; i < n; i++) {
int bi = n * arr[i];
b[bi].push_back(arr[i]);
}


for (int i = 0; i < n; i++)
sort(b[i].begin(), b[i].end());


int index = 0;
for (int i = 0; i < n; i++)
for (int j = 0; j < b[i].size(); j++)
arr[index++] = b[i][j];
}

int main()
{
float arr[]
= { 0.897, 0.565, 0.656, 0.1234, 0.665, 0.3434 };
int n = sizeof(arr) / sizeof(arr[0]);
bucketSort(arr, n);

cout << "Sorted array is \n";
for (int i = 0; i < n; i++)
cout << arr[i] << " ";
return 0;
}

0 comments on commit 59869e6

Please sign in to comment.