How can I fix the int main part for this program to run properly?

#include <iostream>

void print(int a[], int n){
for (int i = 0; i < n; i++)
std::cout << a[i] << " ";
std::cout << "\n";
}

void bubbleSort(int x[], int n){
for(int i = 1; i < n; i++){
for (int j=n-1; j >= i; j--)
if (x[j] < x[j-1])
std::swap(x[j], x[j-1]);
print(x,n);
}
}



int main() {
print({32, 99, 77, 2, 87, 24, 16, 94, 28, 33},10);
return 0;
}


I want to sort the array {32, 99, 77, 2, 87, 24, 16, 94, 28, 33}
first of all, use code blocks. second of all, why not std::array. third of all, whats wrong with it? please be descriptive. fourth of all, i suggest reading up on std::initializer_list
If you want to sort you should probably call your bubbleSort function. The compiler can't implicitly convert the initializer list into an array (int*), create it before the call
1
2
3
4
5
int main() {
	int x[] = {32, 99, 77, 2, 87, 24, 16, 94, 28, 33};
	bubbleSort(x,10);
	return 0;
}
http://ideone.com/Oyz7Ll
Topic archived. No new replies allowed.