Newsgroups: comp.lang.lisp
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!MathWorks.Com!yeshua.marcam.com!news.kei.com!uhog.mit.edu!europa.eng.gtefsd.com!howland.reston.ans.net!math.ohio-state.edu!caen!crl.dec.com!crl.dec.com!pa.dec.com!monet.vill.edu!fulkerso
From: fulkerso@monet.vill.edu (Mike Fulkerson)
Message-ID: <9410131919.AA03878@picasso.vill.edu>
Subject: BFS Tree Problem - HELP!!
Date: Thu, 13 Oct 94 15:19:11 EDT
X-Received: by usenet.pa.dec.com; id AA16481; Thu, 13 Oct 94 12:16:03 -0700
X-Received: by pobox1.pa.dec.com; id AA19304; Thu, 13 Oct 94 12:15:58 -0700
X-Received: from wild.ucis.vill.edu by inet-gw-2.pa.dec.com (5.65/10Aug94)
	id AA12363; Thu, 13 Oct 94 12:06:12 -0700
X-Received: from monet.vill.edu    [153.104.7.173] by WILD.UCIS.VILL.EDU
           with SMTP-OpenVMS via TCP/IP; Thu, 13 Oct 1994 15:04 EST
X-Received: from picasso.vill.edu by monet.vill.edu    (4.1/SMI-4.1)
	id AA08003; Thu, 13 Oct 94 15:02:21 EDT
X-Received: by picasso.vill.edu (ill.edu/Spike-2.0)
	id AA03878; Thu, 13 Oct 94 15:19:12 EDT
X-To: comp.lang.lisp.usenet@decwrl.dec.com
X-Mailer: ELM [version 2.3 PL0]
Lines: 33

Here's my problem:  Given a tree represented by nexted lists, I need to 
replace a subtree with an entirely new subtree.  For example, using
a simple equation, 2*(3+5)+9, parsed into a tree:

              +
             / \
            *   9
           / \       is represented by '(+ (* 2 (+ 3 5)) 9) 
          2   +            (in real life, my trees are much deeper)
             / \
            3   5

The problem is to insert a new subtree (replacing the old) given a node
number using a level-order (breath first) traversal.  Continuing with the
example: given, "replace node 4 with '(* 8 4)," yields:

              +
             / \
            *   9
           / \       is now represented by '(+ (* 2 (* 8 4)) 9) 
          2   *           
             / \
            8   4

Using a depth-first search, this is easily accomplished through recursion and
using a setf.  However, using breath-first requires a queue which internally
duplicates the original structure, and therefore requires another method which
continues to elude me.  Please Email me, or repost a solution.  

Thanx,
Mike Fulkerson
Dept of Computing Sciences
Villanova University
