Skip to content

Instantly share code, notes, and snippets.

@eu90h
eu90h / bst.rkt
Last active December 4, 2017 01:16
A binary search tree implementation in Racket
(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))]
@eu90h
eu90h / gist:d3f1de3f72ad03f1be56
Last active August 29, 2015 14:26
the value of values
(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)])
@eu90h
eu90h / quicksort.rs
Created August 31, 2014 01:54
an implementation of quicksort in rustlang
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);