Skip to content

Commit

Permalink
fix: remove memory issues (#2533)
Browse files Browse the repository at this point in the history
Co-authored-by: realstealthninja <68815218+realstealthninja@users.noreply.github.com>
  • Loading branch information
vil02 and realstealthninja authored Aug 30, 2024
1 parent 9e44b68 commit 519d37f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sorting/counting_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ int *Counting_Sort(int Arr[], int N) {
int *Sorted_Arr = new int[N];

int *Count = new int[max - min + 1];
for (int i = 0; i < max - min + 1; ++i) {
Count[i] = 0;
}

for (int i = 0; i < N; i++) Count[Arr[i] - min]++;

Expand All @@ -37,6 +40,7 @@ int *Counting_Sort(int Arr[], int N) {
Count[Arr[i] - min]--;
}

delete[] Count;
return Sorted_Arr;
}

Expand All @@ -51,6 +55,7 @@ int main() {
Sorted_Arr = Counting_Sort(Arr, N);
cout << "\n\t Sorted Array = ";
Print(Sorted_Arr, N);
delete[] Sorted_Arr;
cout << endl;

return 0;
Expand Down

0 comments on commit 519d37f

Please sign in to comment.