Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

trees.oz defines Infix (in-order) browse of a trees

  • Loading branch information...
commit ee00b402e402d416a82eae7c26898a6a3666cb70 1 parent 93067b4
@lpetit-yseop lpetit-yseop authored
Showing with 35 additions and 0 deletions.
  1. +35 −0 trees.oz
View
35 trees.oz
@@ -0,0 +1,35 @@
+declare
+fun {Infix Tree}
+ case Tree
+ of leaf then nil
+ [] btree(K left:L right:R) then
+ {Append {Append {Infix L} [K]} {Infix R}}
+ end
+end
+
+declare
+fun {Infix Tree}
+ local Helper in
+ fun {Helper Trees}
+ case Trees
+ of nil then nil
+ [] T|Ts then
+ case T
+ of leaf then {Helper Ts}
+ [] btree(K left:L right:R) then {Helper L|K|R|Ts}
+ [] K then K | {Helper Ts}
+ end
+ end
+ end
+ {Helper [Tree]}
+ end
+end
+
+{Browse {Infix
+ btree(4
+ left:btree(2
+ left:btree(1 left:leaf right:leaf)
+ right:btree(3 left:leaf right:leaf))
+ right:btree(5 left:leaf right:leaf))}}
+
+{Browse {Append [1] nil}}
Please sign in to comment.
Something went wrong with that request. Please try again.