Sorting algorithms/Pancake sort: Difference between revisions

Line 2,249:
 
public static void main(String[] aArgs) {
List<Integer> numbers = Arrays.asList( 1, 5, 4, 62, 3, 2, 8, 6, 7 );
System.out.println("Initial list: " + numbers);
pancakeSort(numbers);
Line 2,256:
private static void pancakeSort(List<Integer> aList) {
for ( int i = aList.size() - 1; i >= 0; i-- ) {
int index = IntStream.rangerangeClosed(0, i + 1).boxed().max(Comparator.comparing(aList::get)).get();
if ( index != i ) {
Line 2,266:
private static void flip(List<Integer> aList, int aIndex) {
Collections.reverse(aList.subListif (0, aIndex +> 0 1)); {
System Collections.outreverse(aList.printlnsubList("flip 0.." + (, aIndex + 1 ) + " --> " + aList);
System.out.println("flip 0.." + aIndex + " --> " + aList);
}
}
 
Line 2,274 ⟶ 2,276:
{{ out }}
<pre>
Initial list: [1, 5, 4, 62, 3, 2, 8, 6, 7]
flip 0..76 --> [8, 2, 3, 62, 4, 5, 1, 6, 7]
flip 0..98 --> [7, 6, 1, 5, 4, 62, 3, 2, 8]
flip 0..17 --> [72, 63, 12, 4, 5, 41, 6, 3, 27, 8]
flip 0..84 --> [25, 34, 62, 43, 52, 1, 6, 7, 8]
flip 0..35 --> [61, 2, 3, 2, 4, 5, 1, 6, 7, 8]
flip 0..72 --> [63, 2, 1, 52, 4, 2, 35, 6, 7, 8]
flip 0..13 --> [62, 1, 52, 43, 24, 35, 6, 7, 8]
flip 0..62 --> [32, 21, 42, 53, 14, 65, 6, 7, 8]
flip 0..41 --> [51, 42, 2, 3, 14, 65, 6, 7, 8]
flip 0..5 --> [1, 3, 2, 4, 5, 6, 6, 7, 8]
flip 0..2 --> [3, 1, 2, 4, 5, 6, 6, 7, 8]
flip 0..3 --> [2, 1, 3, 4, 5, 6, 6, 7, 8]
flip 0..1 --> [2, 1, 3, 4, 5, 6, 6, 7, 8]
flip 0..2 --> [1, 2, 3, 4, 5, 6, 6, 7, 8]
</pre>
 
871

edits