A am trying an implementation of some sorting algorithms and I have to calculate how much time they spend. This is the function I wrote:
void bubble_sort(int A[], int len) {
bool ord = false;
for (int i=0; i<len-1 && ord==false; i++) {
ord = true;
for (int j=len-1; j>i; j--) {
if (A[j]-1>A[j]) {
ord = false;
swap(A[j]-1, A[j]);
}
}
}
}
And of course here there is a typical swap() function:
void swap(int x, int y) {
int d;
d = x;
x = y;
y = d;
}
I am not having troubles with Insertion Sort, Selection Sort and Merge Sort. By the way bubble_sort is not sorting the numbers in my array.
I cannot find what's wrong. Do you have any ideas?
void swap(int a[], int x, int y);