Created
April 6, 2018 09:06
-
-
Save prepor/e5656cb739a416ded3c89f98a26b7acf to your computer and use it in GitHub Desktop.
This file contains 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
open Base | |
open With_return | |
type node = { value: int; left: node option; right: node option } | |
let is_bst tree= | |
with_return (fun r -> | |
let rec tick = function | |
| { value; left = None; right = None} -> value | |
| { value; left = Some l; right = None} -> | |
if tick l <= value then value else r.return false | |
| { value; left = None; right = Some ri} -> | |
let a = tick ri in | |
if a > value then a else r.return false | |
| { value; left = Some l; right = Some ri;} -> | |
let a = tick ri in | |
if tick l <= value && a > value then a else r.return false in | |
tick tree |> ignore; | |
true) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment