Sorting World

This world provides tools to experiment with the sorting algorithms. It can be used in two different ways: the first one is naturally to write the required sorting algorithms. But it is also possible to simply use the demo mode of each exercise to observe the behavior of sorting algorithms. It helps understanding the differences between each of them.

Methods available to sorting algorithms

MethodActionCost
[!java]int [/!]getValueCount() [!scala]:Int[/!] Returns the amount of values in the arraynone
[!java]boolean [/!]isSmaller([!java]int [/!]i[!scala]:Int[/!], [!java]int [/!]j[!scala]:Int[/!]) [!scala]:Boolean[/!] Returns true if the content of cell i is strictly smaller than the one of cell jtwo reads
[!java]boolean [/!]isSmallerThan([!java]int [/!]i[!scala]:Int[/!], [!java]int [/!]value[!scala]:Int[/!])[!scala] :Boolean[/!] Returns true if the content of cell i is strictly smaller than the valueone read
[!java]void [/!]swap([!java]int [/!]i[!scala]:Int[/!], [!java]int [/!]j[!scala]:Int[/!]) Swaps the content of cell i and the one of cell jtwo reads, two writes
[!java]void [/!]copy([!java]int [/!]from[!scala]:Int[/!], [!java]int [/!]to[!scala]:Int[/!]) Copy the content of cell 'from' into the cell 'to'one read, one write
[!java]int [/!]getValue([!java]int [/!]idx[!scala]:Int[/!]) Returns the value of cell idxone read
[!java]void [/!]setValue([!java]int [/!]idx[!scala]:Int[/!], [!java]int [/!]value[!scala]:Int[/!]) Sets cell 'idx' to the value one write
[!java]boolean [/!]isSelected() [!scala]:Boolean[/!] Returns whether the current world is selected in the graphical interface.none

History view

It is not enough to sort the array to pass the exercises. Your solution must strictly follow the expected behavior of each exercise. This is enforced by checking that your algorithm needs the same amount of read and write operations to sort the array. When they don't match, understanding the difference between your code and the expected solution can reveal very difficult.

To help in this process, it is possible to graphically explore the history of your sorting algorithm. Switch to the Objective view and use the contextual menu (right click) to switch from the the view of the current state to the view of its history.

The history view is a bit hairly at the first glance, but actually rather simple: The time flows from left to right on this graph, and each row is a cell of your array. The curved lines that go navigate between rows represent a given data value. When two lines cross, this means that two values were swapped at this time stamp; A line fork represent a value copy; When a value is magenta and followed by an interrogation mark (?), it was read using getValue(); If the value is red and followed with an exclamation point (!), it was written using setValue().

This view, inspired from Aldo Cortesi, reveals very helpful understand the inner behavior of sorting algorithms.