template<typename T>
void recursiveBubble(T * arr, int size){
if (bubbleSortAux(arr, size))
return;
else
recursiveBubble(arr, size);
}
template<typename T>
bool bubbleSortAux(T * arr, int size){
T temp;
bool sorted = true;
for (int i = size-1; i >= 0; i--){
if (arr[i] < arr[i-1]){
temp = arr[i-1];
arr[i-1] = arr[i];
arr[i] = temp;
sorted = false;
}
}
return sorted;
}
Recursive bubble sort is very inefficient, so why would I want to? I am eventually going to make my algorithm work for linked lists. Low level stuff, perhaps.
it's not fully recursive,,
you still use looping ( for )...
learning sorting will probably help you figure out how to compare each element to each other
because that what I think I am trying to do when I learn sorting
Just a hint :
avoid linked list if you perhaps thinking that inserting and deleting in linked list is faster than in vector..
because I used to think when to use linked list or vector..
the answer is always vector
under some very specific condition it's linked list
Thanks! I like vectors quite a bit. I will gripe at my professor about the assignment!
Professor wanted us to use recursion for either one of the two bubble sort loops (for either the traditional do-while or the for loop). I chose the first do-while loop to recursify. I was just checking to see if the "recursiveBubble" function is actually recursive, because I'm not actually sure if the "true" bool value here is considered the "base case"? Is it?