I need to develop an algorithm that performs the bubble sort and need help with it! Here is my code so far, can anyone help me figure out what I am doing wrong?
void BubbleSort(int a[], int arraySize)
{
for( int i = 1; i < arraySize; ++i )
{
for( int a = 0; a < arraySize - 1; a++)
{
if( a[a] > a[a+1])
{
int temp;
temp = a[a];
a[a] = a[a+1];
a[a+1] = temp;
}
}
}
}
/*C Program To Sort data in ascending order using bubble sort.*/
#include <stdio.h>
int main()
{
int data[100],i,n,step,temp;
printf("Enter the number of elements to be sorted: ");
scanf("%d",&n);
for(i=0;i<n;++i)
{
printf("%d. Enter element: ",i+1);
scanf("%d",&data[i]);
}
for(step=0;step<n-1;++step)
for(i=0;i<n-step-1;++i)
{
if(data[i]>data[i+1]) /* To sort in descending order, change > to < in this line. */
{
temp=data[i];
data[i]=data[i+1];
data[i+1]=temp;
}
}
printf("In ascending order: ");
for(i=0;i<n;++i)
printf("%d ",data[i]);
return 0;
}