void bubble(int x[])
{
int i, j, temp;
for(i=0;i<=3;i++)
{
for(j=0;j<=3;j++)
{
if (x[j]>x[j+1])
{
temp=x[j];
x[j]=x[j+1];
x[j+1]=temp;
}
This may work but bubble sort loops should look more like this:
Code:
#include<stdio.h>
void bubble(int[],int);
int main()
{
int array[] = {6,3,22,4,111,5};
int i;
bubble(array,sizeof(array)/sizeof(array[0]));
for(i=0;i < sizeof(array)/sizeof(array[0]); i++)
{
printf("%d ", array[i]);
}
return 0;
}
void bubble(int a[], int size)
{
int temp;
for(int i = 0; i < size; i++)
{
for(int ii = 0; ii < size; ii++)
{
if(a[i] < a[ii])
{
temp = a[i];
a[i] = a[ii];
a[ii] = temp;
}
}
}
}
Now also I know that if you want to use bubble sort on a linked list than you must pass the list into the function rather than an array. I don't want to give this example because I have too much to do today. If you get really stuck than I can help at some point this week though.