You are currently viewing Trying Insertion sort in Kotlin

Trying Insertion sort in Kotlin

Can someone please review my code, why its not working. The same code works fine in Javascript.

https://pl.kotl.in/HFn2eGQmO?theme=darcula

val A = mutableListOf(4,8,2,9,5) for (j in 1..A.count() - 1) { val key = A.get(j) var i = j-1 while(i >= 0 && A[i] > key) { A.set(i+1, key) println(A[i+1]) i = i - 1 } A.set(i+1, key) } 

submitted by /u/laggySteel
[link] [comments]