This is a recursive selection sort i would like to be able to change this code without the use of loops into a bubble sort for my assignnment. Ive been trying for an extremelyy long time and im also fairly new to c++ and im struggling. any help would be great...
#include <iostream>
using namespace std;
const int MAX = 10;
void InnerLoop(int values[10], int& min, int j)
{
if(j != MAX)
{
if(values[min] > values[j])
{
min = j;
}
InnerLoop(values, min, j+1);
}
}
void OuterLoop(int values[10], int i)
{
int min = i;
int tempVal = 0;
if(i != MAX)
{
int j = i;
InnerLoop(values, min, j);
tempVal = values[i];
values[i] = values[min];
values[min] = tempVal;
OuterLoop(values, i+1);
}
}
int main()
{
int i = 0;
int values[10] = { 25, 3, 17, 12, 9, 22, 4, 16, 8, 56 };
cout << "Recursive selection sort \n\n";
cout << "values unsorted:\n";
for(int i = 0; i < MAX; i++)
cout << values[i] << "\n";
cout << "\nvalues sorted\n";
OuterLoop(values, i);
for(int i = 0; i < MAX; i++)
cout << values[i] << "\n";
cout << "\nDone\n";
system("pause")
return 0;
}