正在加载图片...
PS 3.1.2: Tree Creation Write a simple Scheme function, fill-tree, that takes as parameters an integer depth,(which is greater than or equal to 2 )and an integer, node-index The function should create a binary tree of the specified depth. The format of the tree should be(node-index(left-child right-child), where left-child and right-child may themselves be trees( this is a recursive definition). At the deepest level of the tree, left-child and right-child are just node indices. For example fill-tree21)=>(1(23) ( fill-tree31)=>(1((2(34)(3(45)) ( fill-tree41)=>(1(2(3(45)(4(56))3(4(56)(5(67)) (define (fi1l-tree depth node -index) f depth 1) node-index (list node-index (list (fill-tree(-depth 1)(+ node-index 1)) (fill-tree(depth 1)(+ node-index 2) pt.24,2003 6410/16413 Even More scheme s there an iterative fill-tree? pt.24,2003 16410/16413 Even more schemeSept. 24, 2003 16.410/16.413 Even More Scheme 7 PS.3.1.2: Tree Creation Write a simple Scheme function, fill-tree, that takes as parameters an integer, depth, (which is greater than or equal to 2) and an integer, node-index. The tree should be (node-index (left-child right-child)), where left-child and right-child the tree, left-child and right-child are just node indices. For example, (fill-tree 2 1) => (1 (2 3)) (fill-tree 3 1) => (1 ((2 (3 4)) (3 (4 5)))) (fill-tree 4 1) => (1 ((2 ((3 (4 5)) (4 (5 6)))) (3 ((4 (5 6)) (5 (6 7)))))) (define (fill-tree depth node-index) (if (= depth 1) node-index (list node-index Sept. 24, 2003 16.410/16.413 Even More Scheme 8 Is there an iterative fill-tree? function should create a binary tree of the specified depth. The format of the may themselves be trees (this is a recursive definition). At the deepest level of (list (fill-tree (- depth 1) (+ node-index 1)) (fill-tree (- depth 1) (+ node-index 2))))))
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有