This is relatively basic but I'm trying to write a function that sorts an array in C++ and I don't want to do it the regular way. I made a loop to find the greatest number in array, store it as "max", save max as the current value in another array and then change the value to zero so that by the time the loop runs the next time, the previous max number will no longer be the maximum, letting the next highest take its place but for some reason, this doesn't work. what did I do wrong?
#include <iostream>
using namespace std;
void mysort(int arr[10]){
int max = 0;
int high[10];
int count;
for (int j=0; j<10; ++j){
for(int i=0; i<10; ++i){
if (arr[i]> max){
max= arr[i];
count=i;
}
}
cout<<"the "<< count+1<<" largest is: "<< max<<"\n";
high[j]= max;
*arr[count]= 0;
}
}
main(){
int pass[10] = {1,2,3,4,5,6,7,8,9,0};
mysort(pass);
}
intinint main()is not optional. Just like thevoidinvoid mysort.*arr[count]= 0;, what do you think it does ?