Created
August 3, 2015 18:40
-
-
Save Akii/495812e5ff4d0826b73c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def isSorted[A](as: Array[A], ordered: (A,A) => Boolean): Boolean = { | |
if (as.length <= 1) true | |
else { | |
@annotation.tailrec | |
def checkSort(n: Int): Boolean = { | |
if (n >= as.length) true | |
else if (!ordered(as(n - 1), as(n))) false | |
else checkSort(n+1) | |
} | |
checkSort(1) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment