We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9e44b68 commit 519d37fCopy full SHA for 519d37f
sorting/counting_sort.cpp
@@ -27,6 +27,9 @@ int *Counting_Sort(int Arr[], int N) {
27
int *Sorted_Arr = new int[N];
28
29
int *Count = new int[max - min + 1];
30
+ for (int i = 0; i < max - min + 1; ++i) {
31
+ Count[i] = 0;
32
+ }
33
34
for (int i = 0; i < N; i++) Count[Arr[i] - min]++;
35
@@ -37,6 +40,7 @@ int *Counting_Sort(int Arr[], int N) {
37
40
Count[Arr[i] - min]--;
38
41
}
39
42
43
+ delete[] Count;
44
return Sorted_Arr;
45
46
@@ -51,6 +55,7 @@ int main() {
51
55
Sorted_Arr = Counting_Sort(Arr, N);
52
56
cout << "\n\t Sorted Array = ";
53
57
Print(Sorted_Arr, N);
58
+ delete[] Sorted_Arr;
54
59
cout << endl;
60
61
return 0;
0 commit comments