diff --git a/Cpp/Bucket_sort.cpp b/Cpp/Bucket_sort.cpp new file mode 100644 index 00000000..0dd781af --- /dev/null +++ b/Cpp/Bucket_sort.cpp @@ -0,0 +1,44 @@ +// C++ program to sort an array using bucket sort +#include +#include +#include +using namespace std; + +// Function to sort arr[] of size n using bucket sort +void bucketSort(float arr[], int n) +{ + + // 1) Create n empty buckets + vector b[n]; + + // 2) Put array elements + // in different buckets + for (int i = 0; i < n; i++) { + int bi = n * arr[i]; // Index in bucket + b[bi].push_back(arr[i]); + } + + // 3) Sort individual buckets + for (int i = 0; i < n; i++) + sort(b[i].begin(), b[i].end()); + + // 4) Concatenate all buckets into arr[] + int index = 0; + for (int i = 0; i < n; i++) + for (int j = 0; j < b[i].size(); j++) + arr[index++] = b[i][j]; +} + +/* Driver program to test above function */ +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; +} diff --git a/README.md b/README.md index cd6de503..a09c6fc0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -

Hacktoberfest 2020

+

Hacktoberfest 2021

*** @@ -17,7 +17,7 @@ To earn your Hacktoberfest tee or tree reward, you must register and make four v

- Link To HactoberFest 2020 + Link To HactoberFest 2021