type 'a tree = Empty | Node of ('a * 'a tree list);; Empty;; Node(3,[Empty]);; type 'a t = Empty | Node of ('a t * 'a * 'a t);; Node(Node(Empty,2,Empty), 1, Node(Node(Empty,4,Empty),3,Empty));; open BinTree;; Node(Node(Empty,4,Empty),3,Empty));; Node(Node(Empty,2,Empty), 1, Node(Node(Empty,4,Empty),3,Empty));; let rec of_list = function | [] -> Empty | x::xs -> Node(Empty,x,of_list xs);; of_list [1;2;3;4;5;6;7;8];; of_list [1;2;3;4;5;6];; let rec size = function | Empty -> 0 | Node(l,_,r) -> size l + 1 + size r;; let t1 = of_list [1;2;3;4;5;6];; size t1;; let rec height = function | Empty -> 0 | Node(l,_,r) -> max (height l) (height r) + 1;; height t1;; Lst.split_at ;; Lst.split_at 3 [1;2;3;4;5;6;7;8];; let rec make = function | [] -> Empty | xs -> let m = Lst.length xs / 2 in let (ys,zs) = Lst.split_at m xs in Node(make ys, Lst.hd zs, make (Lst.tl zs));; make [1;2;3;4;5;6];; make [1;2;3;4;5;6;7];; make [1;2;3;4;5;6;7;8];; insert compare 1 Empty;; insert compare 2 (insert compare 1 Empty);; insert 3 (insert compare 2 (insert compare 1 Empty));; insert compare 3 (insert compare 2 (insert compare 1 Empty));; search_tree;; search_tree compare [1;2;3];; search_tree compare (IntLst.range 0 10);; search_tree compare (IntLst.range 0 7);; search_tree compare (IntLst.range 0 6);; search_tree compare [5;3;6;2;0;1;7];; search_tree compare [5;3;6;0;2;1;7];; let rec flatten = function | Empty -> [] | Node(l,x,r) -> (flatten l) @ (5::(flatten r));; flatten (search_tree compare [5;3;6;0;2;1;7]);; let rec flatten = function | Empty -> [] | Node(l,x,r) -> (flatten l) @ (x::(flatten r));; flatten (search_tree compare [5;3;6;0;2;1;7]);; let sort xs = flatten (search_tree compare xs);; sort [1;3;2;4;9;8];; sort (IntLst.range 0 10000);; sort (Lst.rev (IntLst.range 0 10000));; sort (Lst.rev (IntLst.range 0 100000));; open BinTree;; sort (IntLst.range 0 100000);; Huffman.sort (IntLst.range 0 100000);; let sort xs = BinTree.flatten (BinTree.search_tree compare xs);; sort (IntLst.range 0 100000);; open BinTree;; Huffman.sort;; module H = Huffman;; let sort xs = BinTree.flatten (BinTree.search_tree compare xs);; sort (IntLst.range 0 10000);; sort (Lst.rev (IntLst.range 0 10000));; Lst.rev (IntLst.range 0 10000);; Lst.concat;; Lst.concat [[1;2];[4;3];[5]];; Lst.take_while (fun x -> x < 3) [1;2;3;4;2;1];; Lst.drop_while (fun x -> x < 3) [1;2;3;4;2;1];; Lst.span (fun x -> x < 3) [1;2;3;4;2;1];; Lst.until;; Lst.until (fun x -> x > 10) succ 0;; Huffman.collate ['e';'t';'t';'x'];; compare;; compare 1 2;; compare 1 1;; compare ~-1 1;; compare 1 ~-1;; compare (1,'x') (1,'e');; compare (1,'x') (2,'t');; (3,2,'a');; let text = Strng.of_string "text";; let tree = Huffman.tree text;; #install_printer Huffman.toplevel_printer;; let tree = Huffman.tree text;; Huffman.lookup;; let tab = Huffman.table tree;; Huffman.lookup tab 't';; Lst.map (Huffman.lookup tab) ['t';'e';'x';'t'];; Lst.concat (Lst.map (Huffman.lookup tab) ['t';'e';'x';'t']);;