int* SelectionSort(int* a, int n)
{
int* new_a = newint[n];
new_a[0] = a[0];
int min;
for(int i = 0; i < n; i++)
{
min = i;
for(int j = i + 1; j < n; j++)
{
if(a[j] < new_a[min]) // I compare here
{
min = j;
// here is something missing, I tried a few options but my logic freeze
}
}
/* This is not an option, because I can not change a
int temp = a[i];
a[i] = a[min];
a[min] = temp;
*/
}
return new_a; // return new sorted array
You see I'm stucked in logic how to put sorted numbers in my new array and then return him. I'm sorry for my english I'm still learning. Thanks for all replies.