Welcome to the sorting universe. It allows you to experiment with the existing sorting algorithms. The list of buildins that you can use in your algorithms is available in the world reference documentation ("Help"->"About this world").
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 your algorithm diverges from the expectation, understanding the difference between your code and the expected solution can reveal very difficult. To help in this process, it is posible 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.
A visão do histórico é um pouco bagunçada à primeira vista, mas na verdade é bem simples: o tempo anda da esquerda para a direita neste gráfico, e cada linha é uma célula de sua array. As linhas curvas que navegam entre linhas representam um certo valor de um dado. Quando duas linhas se cruzam, significa que dois valores foram trocados neste momento; uma bifurcação numa linha representa uma cópia de valor; quando um valor é magenta e seguido de uma interrogação (?), foi lido usando getValor(); Se o valor é vermelho e seguido de uma exclamação (!), foi escrito com setValor().
This first sorting algorithm is the most simple one: Bubble sort consists in progressively moving up the smaller elements of the array, as if they were air bubbles moving up to the surface of a liquid. The algorithm traverse the array, and compare any pair of adjacent elements. If two adjacent elements are wrongly sorted, they are swapped. Once the array was completely traversed, the operation starts again from the beginning. When no elements were sorted after a full traversal, it means that the array is completely sorted: the algorithm can stop. Bubble sort is studied because of its simplicity, but it is almost never used in practice because of its bad performance (O(n^2) on average).
The pseudo-code of the BubbleSort algorithm is the following:
do: For each i in [0,len-2] If cells i and i+1 must be swapped, do it while we swapped something during last traversal