Version without JavaScript, read-only: workshops, quizzes and running code are not available here. Full version · Catalogue · Sign in

Sequence

Insertion sort

Core exercise

Write triParInsertion(int[] tableau) that sorts the array in ascending order and returns it.

A workshop goes here: you write and run code in it. It requires JavaScript.

Starting code

Exercices.java

import java.util.Arrays;

public class Exercices {

    public static void main(String[] args) {
        int[] t = { 5, 1, 4, 2, 8 };
        System.out.println(Arrays.toString(triParInsertion(t)));
    }

    public static int[] triParInsertion(int[] tableau) {
        // TODO
        return tableau;
    }
}

The core exercise is validated in the workshop, which requires JavaScript.

Hint 1

Just like sorting the cards in your hand: take the current element and slide it to the left as long as its neighbour is larger.