fun linearSearch(array: List<Int>, number: Int): Int {
for (i in array.indices) {
if (array[i] == number) {
return i
}
}
return -1
}
fun main() {
val array = listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
val number = 8
val index = linearSearch(array, number)
if (index == -1) {
println("Poszukiwanej wartosci nie ma w liscie")
} else {
println("Poszukiwana wartosc znajduje sie pod indeksem $index")
}
}
ZnVuIGxpbmVhclNlYXJjaChhcnJheTogTGlzdDxJbnQ+LCBudW1iZXI6IEludCk6IEludCB7CiAgZm9yIChpIGluIGFycmF5LmluZGljZXMpIHsKICAgIGlmIChhcnJheVtpXSA9PSBudW1iZXIpIHsKICAgICAgcmV0dXJuIGkKICAgIH0KICB9CgogIHJldHVybiAtMQp9CgpmdW4gbWFpbigpIHsKICB2YWwgYXJyYXkgPSBsaXN0T2YoMSwgMiwgMywgNCwgNSwgNiwgNywgOCwgOSwgMTApCiAgdmFsIG51bWJlciA9IDgKCiAgdmFsIGluZGV4ID0gbGluZWFyU2VhcmNoKGFycmF5LCBudW1iZXIpCgogIGlmIChpbmRleCA9PSAtMSkgewogICAgcHJpbnRsbigiUG9zenVraXdhbmVqIHdhcnRvc2NpIG5pZSBtYSB3IGxpc2NpZSIpCiAgfSBlbHNlIHsKICAgIHByaW50bG4oIlBvc3p1a2l3YW5hIHdhcnRvc2Mgem5hamR1amUgc2llIHBvZCBpbmRla3NlbSAkaW5kZXgiKQogIH0KfQ==