void bubble(int a[], int n) {
for(i=0;i<n;i )
{
for(j=i 1;j<n;j )
{
if(a[j]<a[i])
{
temp=a[i 1];
a[i 1]=a[j];
a[j]=temp;
}
}
}
}
Not working? Please anyone help to resolve this issue. actually I am beginner.
CodePudding user response:
Bubble sort works on the repeatedly swapping of adjacent elements until they are not in the intended order. It is called bubble sort because the movement of array elements is just like the movement of air bubbles in the water. Bubbles in water rise up to the surface; similarly, the array elements in bubble sort move to the end in each iteration.
Use this code:
void bubble(int a[], int n)
{
for(i=0;i<n;i )
{
for(j=i 1;j<n;j )
{
if(a[j]<a[i])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
}
For more info click here.