4int Max(
int Arr[],
int N) {
6 for (
int i = 1; i <
N; i++)
12int Min(
int Arr[],
int N) {
14 for (
int i = 1; i <
N; i++)
20void Print(
int Arr[],
int N) {
21 for (
int i = 0; i <
N; i++) cout << Arr[i] <<
", ";
24int *Counting_Sort(
int Arr[],
int N) {
25 int max = Max(Arr, N);
26 int min = Min(Arr, N);
27 int *Sorted_Arr =
new int[
N];
29 int *Count =
new int[max - min + 1];
30 for (
int i = 0; i < max - min + 1; ++i) {
34 for (
int i = 0; i <
N; i++) Count[Arr[i] - min]++;
36 for (
int i = 1; i < (max - min + 1); i++) Count[i] += Count[i - 1];
38 for (
int i = N - 1; i >= 0; i--) {
39 Sorted_Arr[Count[Arr[i] - min] - 1] = Arr[i];
40 Count[Arr[i] - min]--;
48 int Arr[] = {47, 65, 20, 66, 25, 53, 64, 69, 72, 22,
49 74, 25, 53, 15, 42, 36, 4, 69, 86, 19},
53 cout <<
"\n\tOrignal Array = ";
55 Sorted_Arr = Counting_Sort(Arr, N);
56 cout <<
"\n\t Sorted Array = ";
constexpr uint32_t N
A struct to represent sparse table for min() as their invariant function, for the given array A....