1. in sort_array you create a useless copy (result) of the original array. Return array instead. |
In fact, you don't need to return
array at all. The contents of the memory that
array points to are changed by the function to contain the sorted data, but the memory address that's stored in
array isn't changed at all. The calling code will already see the new, sorted contents of
array once the function has completed.
4. the statement for(double i=0; i<250; i++) is wrong: i must be of integral type, and also you will get an out of bounds because the select array has 100 elements, not 250. |
One way to help prevent making mistakes like this is to declare a const variable equal to the array size you're using, and use that variable everywhere. So:
1 2 3 4 5 6 7 8 9 10
|
const int ARRAY_SIZE = 100;
// ...
for(i=0; i<ARRAY_SIZE; i++)
{
for(j=i; j<ARRAY_SIZE; j++)
{
// ...
|
If you use ARRAY_SIZE everywhere, there's no danger of you accidentally using the wrong number. Plus, if you decide to change the array size, you just have to change it in one place, not in every loop you're written.
EDIT: An even better way is to use std::vector, rather than C-style arrays.