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
(struct bst-node (val left right) #:transparent #:mutable) | |
(define (bst-add tree value) | |
(if (null? tree) (bst-node value null null) | |
(let ([x (bst-node-val tree)]) | |
(cond | |
[(= value x) tree] | |
[(< value x) (if (null? (bst-node-left tree)) | |
(set-bst-node-left! tree (bst-node value null null)) | |
(bst-add (bst-node-left tree) value))] |
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
(define (f x y) | |
(list (add1 x) (add1 y))) | |
(define (g x y) | |
(values (add1 x) (add1 y))) | |
(define x 1) | |
(define y -1) | |
(let* ([values (f x y)] | |
[new-x (first values)] | |
[new-y (second values)]) |
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
fn choose_pivot(left: uint, right: uint) -> uint { | |
if left < right+1 { | |
std::rand::task_rng().gen_range(left, right+1) | |
} else { | |
left | |
} | |
} | |
fn partition(data: &mut[int], left: uint, right: uint) -> uint { | |
let pivotIndex: uint = choose_pivot(left, right); |
NewerOlder