java - Selection Sort with an ArrayList of objects -
I'm having some problems like this, it will only display the first file correctly. Anyone sees what I am doing wrong? I am trying to understand it for hours and I do not know what I am doing.
Public Zero Type () {int i; // loop end of control end; // The final position in array list int max; // position where the previous alphabet file name is max = 0; // The biggest situation is so far first, because I did not check // I thought I would start at the end and (= final file = list.size () - 1; final> gt; = 0; -) {for (i = 0; i & lt; fileList.size (); i ++) {if (fileList.get (max) .getFileName (). Compare (fileList.get (i) .getFileName () )> 0) Max = i; } // Last alphabet Pixfile tempPix = fileList.get (last) in the last position with swap pixfile; FileList.set (last, fileList.get (max)); FileList.set (max, tempPix); // I thought I repeat till last = 0 and the array list is sorted}}
should be a loop for the internal (int i = 0; i & lt; = last; i ++) because you are still choosing the best from being ranked . After all, you have already sorted the previous iteration of the external loop. Also, you are not resetting the value of max in each walk, so for the loop before the inner, max = 0; Write too If you are too lazy to write the sorting algorithm, you should always Arrays.sort () or Collections.sort () < / Code>
Comments
Post a Comment