That's exactly right. I guess its an exercise for the reader to update this to count the internal nodes as well. :-)

Kind regards

Don

By on 5/17/2008 5:11 AM ()

Here's the trivial "fix" to count all the internal nodes as well. [:)]

1
2
3
4
5
6
 let rec sizeContAcc acc tree cont =
  match tree with
  | Tip _ -> cont (1+acc)
  | Node(_,treeLeft,treeRight) -> sizeContAcc (1+acc) treeLeft (fun accLeftSize -> 
                                  sizeContAcc accLeftSize treeRight cont)

-Matteo

By on 5/25/2008 11:51 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper