Advertisement
Guest User

Untitled

a guest
Dec 14th, 2013
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
F# 0.65 KB | None | 0 0
  1. open System
  2.  
  3. type NodeType = int
  4. type Tree =
  5.     | Nil
  6.     | Node of NodeType * Tree * Tree
  7.  
  8. let createTree() =
  9.     Node(1, Node(2, Node(4, Nil, Nil),
  10.                     Node(5, Nil, Nil)),
  11.             Node(3, Node(6, Nil, Nil),
  12.                     Node(7, Node(9, Nil, Nil),
  13.                             Node(8, Nil, Nil))
  14. ))
  15.  
  16. let rec inOrder visit tree =
  17.     match tree with
  18.     | Nil -> ()
  19.     | Node(v, left, right) ->
  20.         inOrder visit left
  21.         visit v
  22.         inOrder visit right
  23.  
  24. let mutable result = []
  25. let sum v =
  26.     result <- result @ [v]
  27.  
  28. let treeObj = createTree()
  29. inOrder sum treeObj
  30. Console.ReadLine() |> ignore
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement