开发者

traversal through a tree in scheme

ok i have this tree:

              a6
           /   |  \ 
        a1    a2   p1
                 /    \
              a1       a2   

and i need some code to traverse it. in a deep-list represantati开发者_运维技巧on it's like this right? (a1 a2 (a1 a2))? i already got a method that returns the childerns nodes. for example if i call it, (function tree a6) = (a1 a2 p1) any ideas?


I'm a little shady on what exactly you are asking, but I will try to get you started.

The deep-list representations of the tree structure you mentioned should look something like this:

 '(a6 (a1) (a2) (p1 (a1) (a2)))

About a year ago I wrote a few blog articles that you may find useful. Trees in Scheme: Representation and Trees in Scheme: Parsing.

In the "Parsing" article, I demonstrate the use of mutual recursion (a recursive technique in which two procedures are defined in terms of each other) to effectively parse trees. This should be helpful.

Finally, I also recommend you read chapter 18 of Simply Scheme for a somewhat thorough introduction to this topic.

Good luck.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜