I am trying to write a user-defined function to sort by bubble sort. My code is as follows:
void bubblesort(int arr, int n)
{
for( int i=0; i<n-1; i++)
{
for( int j=0; j<n-i-1; j++)
{
if( arr[j]>arr[j+1])
{
swap(&arr[j], &arr[j+1]);
}
}
}
}
The error thrown is like this: if( arr[j]>arr[j+1]) ~^ error: subscripted value is neither array nor pointer nor vector
Any ideas on how to fix it?
Aucun commentaire:
Enregistrer un commentaire