arrays in c language
Bubble sort in c programming arranges in ascending or descending order?
void bubble(int x[], int n)
{
int hold, j, pass;
int switched = TRUE;
for (pass=0;pass %26lt; n-1 %26amp;%26amp; switched == TRUE; pass++)
{
switches= FALSE;
for (j=0;j %26lt; n-pass-1; j++)
if(x[j] %26gt; x[j+1])
{
switched = TRUE;
hold = x[j];
x[j] = x[j+1];
x[j+1] = hold;
}
}
}
Reply:descending order i guess
Reply:Now in general It works to arrange the array in ascending order.
The code portion
/*if(a[i]%26gt;a[i+1])then
swap;*/ does the main job.If you change the %26gt; sign to %26lt; sign then it will arrange the array in descending order.
Reply:it depends on your code.
you can make it in ascending or descending order.
Reply:Its depends on how you are implementing the bubble sort. There is no fixed rule. Its up to the programmer how he wants to implement it. Both ascending and descending order are valid. This applies to all the sorting algorithms.
Reply:Both the way you can sort. It depends upon your code.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment