From 717f5c8f01c1d5559320e118ccc8eabdf602e8ff Mon Sep 17 00:00:00 2001 From: Krishna Vedala Date: Tue, 26 May 2020 12:31:49 -0400 Subject: [PATCH] fix dynamic array --- sorting/bucket_sort.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sorting/bucket_sort.cpp b/sorting/bucket_sort.cpp index f120f04fc..c43865281 100644 --- a/sorting/bucket_sort.cpp +++ b/sorting/bucket_sort.cpp @@ -6,7 +6,7 @@ // Function to sort arr[] of size n using bucket sort void bucketSort(float arr[], int n) { // 1) Create n empty buckets - std::vector b[n]; + std::vector *b = new std::vector[n]; // 2) Put array elements in different buckets for (int i = 0; i < n; i++) { @@ -21,6 +21,7 @@ void bucketSort(float arr[], int n) { int index = 0; for (int i = 0; i < n; i++) for (int j = 0; j < b[i].size(); j++) arr[index++] = b[i][j]; + delete[] b; } /* Driver program to test above funtion */