My assignment is to make a recursive bubble sort, but I'm not allowed to use any loops.... In fact, the only loop I can use is in the main when I call the function.
I'm totally clueless as to what to do.
This was an example of a bubble sort we worked on in class, I just have no idea how to do it without loops.
#include <iostream>
#include <cmath>
#include <ctime>
using namespace std;
void swap(int& x, int& y) {
int t = x; x = y; y = t;
}
int main(void) {
clock_t start,finish;
double time;
start = clock();
const int size = 400000;
int a[size];
for(int j = 0; j < size; j++)
a[j] = rand();
for(int j = 0; j < size; j++)
for(int i = 0; i < size - 1 - j; i++)
if(a[i] > a[i+1])
swap(a[i], a[i+1]);
finish = clock();
time = (double(finish)-double(start))/CLOCKS_PER_SEC;
cout << "for size = " << size << ", time = " << time << endl;
return 0;
}