Hello, I've just started my adventure with c++. I found a task: get weight of 10 apples form keyboard and sort it high to low. I did it, but I've got no idea what's wrong. Could you help me? :)
(I work with dev c++)
void sort(int T[], int n)
{
int k;
double pom;
for (int i=0; i<9; i++)
{
k=i;
for (int j=i+1; j<10; j++)
if (T[j]<T[k]) k=j;
pom=T[k];
T[k]=T[i];
T[i]=pom;
return T[];
}
}
int main() {
int T[];
int n=10;
int i;
for (i=0; i<n; i++)
{
cout<<"Write weight of apple number "<<i+1<<": ";
cin>>T[i];
}
cout<<sort(T[], 10);
return 0;
}
There is a function in algorithm called std::sort you could use with a custom sort like this std::sort(T , T+10 , [](constint &lhs , constint &rhs ){ return lhs > rhs; };
The custom sort is called a lambda