Advertisement
Muhammad_Farroos

Recursive Function

Mar 18th, 2022
995
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 0.42 KB | None | 0 0
  1. fun isSorted(a: IntArray, index: Int): Boolean {
  2.     if (index == 1) {
  3.         return true
  4.     }
  5.     return if ((a[index - 1] < a[index - 2]) || a.size > 50) false
  6.             else isSorted(a, index - 1)
  7. }
  8.  
  9. fun main() {
  10.     val a = intArrayOf(1, 2, 3, 4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,70,36,37,38,39,40,41,42,43,44,45,45,47,48,49,50)
  11.     println(isSorted(a, a.size))
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement