Several things:
1.) You have
const int SIZE = 3
on line 5, but you never use it.
2.) Nitpicky, but why is the array an array of doubles?
3.) Your swap() argument list makes no sense. I would pass an array, and then an integer type to represent the number of elements.
void swap(int array[], const unsigned short size) {
4.) I don't know why there's confusion regarding the difference between swap and sort. In a way, there is no difference, because you are sorting the array by swapping the elements.
5.) Ideally, the swap (or sort) function should work for an arbitrarily sized array.
6.) You have some weird stuff going on in main.
Here's an example of an un-optimized bubble sort function, which sorts an array by swapping the elements.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
void bubblesort(int array[], const unsigned short size) {
bool sorted;
do {
sorted = true;
for(unsigned short i=0; i<size-1; ++i) {
if(array[i] > array[i+1]) {
sorted = false;
int temp = array[i];
array[i] = array[i+1];
array[i+1] = temp;
}
}
}while(!sorted);
}
|