
Am Montag, 2. März 2009 15:18 schrieb friggin friggin:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=1989#a1990
Is the algorithm wrong ar am I using it wrong?
a) what if there are more random numbers than elements in the tree? I suggest shuffle' (Leaf e) _ = [e] b) You don't cater for the case when the number of the element to be extracted is larger than the size of the tree-1 I suggest giving a first case of extractTree n t@(Node c _ _) | c <= n = extractTree (n `mod` c) t to extractTree
Also, is the second argument to shuffle supposed to eb random numbers, ie the function should be used in the IO Monad?
The function is pure. Whether you use it in the IO monad or not depends on whether the input lives inside the IO monad.