Source: https://www.fil.univ-lille.fr/~L1S2API/TD/tdTri.pdf