Write the presice code below in C including the cieling func
Write the presice code below in C++ (including the cieling function):
Write the preside code below in C++ (including the ceiling function): STOOGESORT(A[0..n-1]): if n = 2 and A[0] > A[1] swap A[0] doubleheadarrow A[1] else if n > 2 m = [2n/3] STOOGESORT (A[0 ..m - 1]) STOOGESORT(A[n - m..n - 1]) STOOGESORT (A[0 ..m - 1])Solution
#include <iostream>
using namespace std;
void print_array (int a[], int n)
{
for (int i = 0; i < n; ++i)
{
cout << a[i] << \" \";
}
cout << endl;
}
void stooge_sort (int a[], int i, int j)
{
if (a[j] < a[i])
{
swap (a[j], a[i]);
}
if ((j - i + 1) > 2)
{
int t = (j - i + 1) / 3;
stooge_sort (a, i, j - t);
stooge_sort (a, i + t, j);
stooge_sort (a, i, j - t);
}
}
int main()
{
int a[] = {1, 2, 40, 22, 15, 16, 29, 2, 0, 160};
cout << \"Array Initially : \";
print_array (a, 10);
stooge_sort (a, 10);
cout << \"Sorted Array : \";
print_array (ar, 10);
return 0;
}
![Write the presice code below in C++ (including the cieling function): Write the preside code below in C++ (including the ceiling function): STOOGESORT(A[0..n-1] Write the presice code below in C++ (including the cieling function): Write the preside code below in C++ (including the ceiling function): STOOGESORT(A[0..n-1]](/WebImages/7/write-the-presice-code-below-in-c-including-the-cieling-func-993228-1761510971-0.webp)