I have a project due soon and im confused on the sort function. i have the sort function from my book and i would like to put it in descending order for any array.
void sort(double x[], int n)
{
int m;
double hold;
for (int k = 0; k <= n-2; ++k)
{
m = k;
for (int j = k + 1; j <= n - 1; ++j)
{
if (x[j] < x[m])
m = j;
}
hold = x[m];
x[m] = x[k];
x[k] = hold;
}
return;
}
Hey bud. I too have a project due next week that involves sorting. I struggled for a while, but then I learned there is a std library function called sort. Check out this link, there's a lot in there, but look for what you're trying to do and plug in what you need!
Check out this link, there's a lot in there, but look for what you're trying to do and plug in what you need!
It is very obvious that the OP has to create his/her own sort function. Even if he/she could, you are not being much of a help. All you do is give the OP a link to an article. A reference would have been better (simpler): http://www.cplusplus.com/reference/algorithm/sort/
std::sort() is also simple to explain so you could've easily explained yourself with an example.
Anyways, here you go OP (assuming you're using bubble sort):