WAP to insert an element in the already sorted list. The new element should be inserted in its appropriate position according to the list. The element must be entered by the user not position. for example: [3,6,8,9,12,17,18,23]
Example: insertion sort
function insertionSort(vetor) {
let current;
for (let i = 1; i < vetor.length; i += 1) {
let j = i - 1;
current = vetor[i];
while (j >= 0 && current < vetor[j]) {
vetor[j + 1] = vetor[j];
j--;
}
vetor[j + 1] = current;
}
return vetor;
}
insertionSort([1, 2, 5, 8, 3, 4])