0

Insertion sort algorithm

is this code snippet correct a [5]=[4,2,6,1,10] for (i=0; i <n; i++) { for (j=i+1; j <n; j++) { if (a [i]>a [j]) { swap a [i] & a [j] } } }

6th Jan 2019, 12:23 PM
Initiator
1 Respuesta
+ 1
This looks more like a bubble sort. Insertion sort would find the smallest element first, put it in the first position in the list, then cycle over the remaining element and repeat.
6th Jan 2019, 2:15 PM
Tibor Santa
Tibor Santa - avatar