Skip to content

Commit 717f5c8

Browse files
committed
fix dynamic array
1 parent 0d8e015 commit 717f5c8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

sorting/bucket_sort.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// Function to sort arr[] of size n using bucket sort
77
void bucketSort(float arr[], int n) {
88
// 1) Create n empty buckets
9-
std::vector<float> b[n];
9+
std::vector<float> *b = new std::vector<float>[n];
1010

1111
// 2) Put array elements in different buckets
1212
for (int i = 0; i < n; i++) {
@@ -21,6 +21,7 @@ void bucketSort(float arr[], int n) {
2121
int index = 0;
2222
for (int i = 0; i < n; i++)
2323
for (int j = 0; j < b[i].size(); j++) arr[index++] = b[i][j];
24+
delete[] b;
2425
}
2526

2627
/* Driver program to test above funtion */

0 commit comments

Comments
 (0)