I wrote the count sort code but it is showing me weird output, can you tell where I am wrong ??
#include <bits/stdc++.h>
using namespace std;
void CountSort(int a[], int n, int k)
{
int count[k + 1]={0};
int b[n];
for (int i = 0; i < n; i++)
{
++count[a[i]];
}
for (int i = 1; i <= k; i++)
{
count[i] += count[i - 1];
}
for (int i = 0; i >= 0; i--)
{
b[count[a[i]]-1] = a[i];
--count[a[i]];
}
for (int i = 0; i < n; i++)
{
a[i] = b[i];
}
}
int main()
{
int a[] = {2, 1, 1, 0, 2, 5, 4, 0, 2, 8, 7, 7, 9, 2, 0, 1, 9};
CountSort(a, 17, 9);
cout<<"The sorted array is -> "<<a;
return 0;
}
It gives output like this -
The sorted array is -> 0x7bfdd0