This site requires JavaScript, please enable it in your browser!
Greenfoot back
Asiantree
Asiantree wrote ...

2017/4/28

Help with sorting an array of objects

1
2
danpost danpost

2017/4/30

#
Asiantree wrote...
Something like this? < Code Omitted >
No. Everything except for line 4 after the '&&' should be exactly the same as in the 'sorrByTotal' method.
Asiantree Asiantree

2017/4/30

#
Like this?
while (n > 0 && infos[n-1].getTotal() < infos[n].getTotal()) 
Sorry I am extremely close to finishing this, and your help has definitely been appreciated.
danpost danpost

2017/4/30

#
Asiantree wrote...
Like this?
while (n > 0 && infos[n-1].getTotal() < infos[n].getTotal()) 
Sorry I am extremely close to finishing this, and your help has definitely been appreciated.
I think your comparisons of the totals is not correct for the order you want (change the 2nd '<' to '>'). FYI, you either switch the order of elements compared or switch the comparison operator, but not both, as that just results in no change in the comparison at all.
You need to login to post a reply.
1
2