Write the INSERT function which places an X element inside an array that contains N elements sorted in ascending order, so as to obtain an array with N + 1 elements sorted in ascending order. The dimension of the array is incremented in the INSERT function.

Write a program that takes advantage of the previously written functions to test the INSERT function.


Difficulty level
Video recording
This exercise is mostly suitable for students
int insert(int X, int T[], int N)
{
    int i;
    for(i=N; i>0 && T[i-1]>X;  i--)
        T[i]=T[i-1];
    T[i]=X;
    return N+1;
}

Back to the list of exercises
Looking for a more challenging exercise, try this one !!
Kruskal Algorithm - Minimal Spanning Tree