sorting smallest function, need hlep

Expected output
after·sorting·range·0·to·9↵
[0]:·'aa'↵
[1]:·'aa'↵
[2]:·'bb'↵
[3]:·'bb'↵
[4]:·'cc'↵
[5]:·'ee'↵
[6]:·'ee'↵
[7]:·'gg'↵
[8]:·'yy'↵
[9]:·'zz'↵

real output
after·sorting·range·0·to·9↵
[0]:·'zz'↵
[1]:·'yy'↵
[2]:·'gg'↵
[3]:·'ee'↵
[4]:·'ee'↵
[5]:·'cc'↵
[6]:·'bb'↵
[7]:·'bb'↵
[8]:·'aa'↵
[9]:·'aa'↵

I tried my best to figure it out, but even though I put an hour, I couldn't fix it... plz help. I am pretty sure my second for loop is wrong, I tried everything that I knew, but it was giving me wrong answers.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
void sort(string destination[], int low, int high) {
    int i;
    int j;
    int smallest;
    string temp;
    for ( i = low; i <= high; i++) {
        smallest = i;
        for (j = i; j <= high; j++) {
            if (destination[j] > destination[smallest]) {
                smallest = j;            
            }
        }
        temp = destination[smallest];
        destination[smallest] = destination[i];
        destination[i] = temp;
    }
    
    return ;
}
Last edited on
destination[j] > destination[smallest] You will actually find largest that way...
Topic archived. No new replies allowed.