https://kotlinlang.org logo
#kotlin-native
Title
# kotlin-native
m

Muhammet Emin Gündoğar

05/26/2022, 9:22 AM
Copy code
fun <T:Comparable<T>>linearSearch(list:List<T>, key:T):Int?{
    for ((index, value) in list.withIndex()) {
        if (value == key) return index
    }
    return null
}
I was learning linear search algorithm in kotlin but there is a thing why we used comparable interface here can you explain logic of comparable part?
n

napperley

05/30/2022, 9:52 PM
This isn't Kotlin Native related. Use the #random channel instead.
2 Views