La figure 1.2 illustre l'opération effectuée par l'algorithme Insertion.
Algorithme Insertion
Input:
int N;
int tbl[N];
int i;
int k;
Output:
// pas de retour
Begin
int ei,j;
// Insertion de tbl[i] a la place k
// -> memorise tbl[i]
ei=tbl[i];
// -> rotation - decale les elements pour pouvoir inserer tbl[i]
for (j=i-1;j>=k;j=j-1)
{
tbl[j+1]=tbl[j];
}
// -> ecrit ei en k
tbl[k]=ei;
End