I am having trouble coding a simple Bubblesort algorithm in C++ on Xcode. A particular problem is getting the length of the array, and I get an error saying "sizeof on array function will return size of int* instead of int[]." What does this mean? I tried to test the algorithm on the array {33,60,55,8,26} but am puzzled by how to construct an array length function.
#include <iostream>
#include <array>
using namespace std;
#define ARRAY_SIZE(array) (sizeof((array))/sizeof((array[0])))
void swap(int n1, int n2){
int temp = n1;
n1 = n2;
n2 = temp;
}
int count(int a[]){
int len=0;
for(int i = 0; i <= 20; i++){
if(a[i] >= 0){
len++; //len=len+1
}
}
return len;
}
template <size_t N>
void BubbleSort( int a[], size_t len ){
for(int i = 0;i <= len;i++){
if(a[i] > a[i+1]){
swap(a[i],a[i+1]);
}
}
}
void printr(int arr[]){
for(int i = 0; i <= len; i++){
cout<<arr[i]<<"\n";
}
}
int main(int argc, const char * argv[]) {
int arr[] = {33,60,55,8,26};
BubbleSort(arr, ARRAY_SIZE(arr));
printr(arr);
return 0;
}