Thursday, 15 March 2012

random - Walk randomly through a binary tree? -


I am creating a program that takes a tree and randomly selects a branch (left or right) and A list of those values Is it not working for any reason any help? Example:

  ~ (RandWalk (tree 1 (leaf 2) (address 3)) (1 2)   < P> This is what I have done so far:  
  (define (rand-walk tr) (if (empty-tree? Tr) '() (if (pana? Tr) Tr (if (equals? (Random 1) 0 (opposition (root-value tr) (original-value (left-subtree tr)) '()) (opposition (root-value tr) (root-value (Right-subtitles tr))) '()))))    

There are several problems with your code here, there is a proper implementation:

  (Par Speak (Rand-watt tr) (code (empty-tree? Tr) '()) ((address? Tr) (list (root-value tr ()) ((equals? (Random 1) 0) (Opposition (root-value tr) (rand-walk (left-subtree tr)) (and (opposition (root-value tr) (rand-walk   

if I am writing this So I use the tail's recursive approach:

  (define (rand-walk (walk (walking (('l' ()) (tr () (( Value (root-value tr)) (if (tree? Tr) (reverse (opposition value l)) (walking (opposition value l)) ((if Nothing? (Random 1)) left-subtitle right-subtree)))))))    

No comments:

Post a Comment