Trees 
Author Message
 Trees

Quote:
> I have a tree represented by a list of lists.
> I want to modify any subtree.
> I represent location of the subtree by a path from the root.

> eg if path is [2 1 3]
>    i want to do
>    newsubtree->tree(2)(1)(3);

> How can I do this for any tree<path1,path2,...,pathn> ?

You want to define a procedure with three arguments

        define update_tree(tree, path, subtree);

The key point to note is that if path is a list of N numbers
[p1 p2 p3 ... pN], the first N-1 numbers are used to select branches
down the tree and the last one updates the pNth branch from the last
selected node.

So just iterate down the path selecting branches till you have only
one number left in the path, in which case you do the update.

You should be able to contstruct the code from that, using the fact that
you have only one item in a list if

        tl(list) == []

You might find "for tail on list do ... endfor" useful.

Aaron



Mon, 18 May 1998 03:00:00 GMT  
 Trees
Hiya!

I have a tree represented by a list of lists.
I want to modify any subtree.
I represent location of the subtree by a path from the root.

eg if path is [2 1 3]
   i want to do
   newsubtree->tree(2)(1)(3);

How can I do this for any tree<path1,path2,...,pathn> ?

is there a clever way to do this, without rebuilding the tree.

Yours,
Liam Parnell.



Mon, 18 May 1998 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Self-Adjusting Binary Search Trees (Splay Trees)

2. Self-Adjusting Binary Search Trees (Splay Trees)

3. TREE browse .. Ultra Tree Template - Att Marius

4. cast iron tree stand for Christmas tree

5. Alternate solution to tree -> tree problem

6. B plus trees and b star trees

7. Searching for B-tree/B*-tree package...

8. Need to build a tree buttom-up (parse tree)

9. BLT Tree -vs- BWidget Tree

10. AVL Tree,Binary Tree,Sorting..

11. ANNOUNCE: tree-3.3 - tree widget for Tk-3.3b3

12. searching trees (AVL, 2-3-4 and red-black trees)

 

 
Powered by phpBB® Forum Software