Created
July 17, 2010 17:47
-
-
Save stakx/479694 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
// Dummy definition of the binary tree: | |
type Deque<'a> = | |
| Empty | |
| Node of Deque<'a> * 'a * Deque<'a> | |
// Traverse from "front" (L) to "back" (R): | |
let rec items D = | |
match D with | |
| Empty -> Seq.empty | |
| Node(L,x,R) -> seq { | |
yield! items(L) | |
yield x | |
yield! items(R) | |
} | |
// Test tree; this reflects the insertion of elements 1, 2, 3 (in this order) at the front: | |
let T = Node( Node(Empty, 3, Empty), | |
2, | |
Node(Empty, 1, Empty) ) | |
// The following would output something like, "val it : seq<int> = seq [3; 2; 1]" | |
let ts = items T |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment