0

Im so close to completing this program and i just need someone to look over it and tell me whats wrong. Im getting close to my wits end but if they could help me i would send them my code to look at so as to not post the entirety. i think it might be my sorting: { // TODO: implement an O(n^2) sorting algorithm

for (int i = 0; i < n - 1; i++)
{
    int min = 0;

    for (int j = 1; j < n; j++)
    {
        if(values[min] > values[j])
        {
            min = j;
        }

        int temp = values[min];
        values[min] = values[i];
        values[i] = temp;
    }
}
return;

}

1
  • There is no problem in showing the part of the code in which you think the error is
    – MARS
    Commented Mar 20, 2017 at 21:05

1 Answer 1

1

This is a Selection Sort algorithm, I think the problem is in the declaration

int min = 0;

Every time the outermost loop min is always zero, what interests us is that there is a variable that stores the min value, if you think about it a little you should be

int min = i;

I hope this helps

1
  • it did help correct the smiley i was trying to correct and now another one is popping up and i think its a search related issue-___-
    – Chris
    Commented Mar 20, 2017 at 22:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .