Hello!!
Code:
void bubblesort(int n, double *x)
{ int i, j;
for (i=1 ; i<=n-1 ; i++)
for (j=n-1 ; j>=i ; j--)
if (x[j-1] > x[j])
swapd(&x[j-1], &x[j]);
}
I want to modify the upper bubblesort in order to have a circular behaviour.
I tried this but it doesn't seem to work right:
Code:
void bubblesort(int n, double *x, int point)
{
int i,j;
for(i=point+1 ; i!=point-1 ; i = (i+1)%n)
for(j=point-1 ; j!=i ; j = ((j<=0) ? (n-1) : (j-1)))
if (x[((j<=0) ? (n-1) : (j-1))] > x[j])
swap(&x[((j<=0) ? (n-1) : (j-1))], &x[j]);
In both cases swap is:
Code:
void swapd(double *a, double *b)
{ double temp;
temp = *a;
*a = *b;
*b = temp; }
Variable point, is the point from where I want to start sorting my array, from the element x[point] till x[point-1].
As u can see when point is equal to zero the circular bubblesort should work as the typical one (1st code example).
BUT mine doesn't work ..
Does anybody know what is wrong with it?
Thanks in advance!!