Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #33450

Re: searching a tree of objects

Newsgroups comp.lang.java.programmer
Date 2016-01-07 21:59 -0800
References <a8beac79-4ac8-4abd-b680-ab4a3112dd51@googlegroups.com>
Message-ID <531d0446-8946-428b-a239-981db96a1bda@googlegroups.com> (permalink)
Subject Re: searching a tree of objects
From mike <mikaelpetterson@hotmail.com>

Show all headers | View raw


I will make some simplifications and clarifications:


I have two java lists containing names ( parents and chilren). So when I have Equipment in childlist the same index in parent list will be Rootype.

Given is a "path" describing the way to a "leaf". See below.

{RootType,DfcDdd,DbcDevice,Nhost}

This what I want to search for using above mentioned list.

                                  Rootype
                                    |
                  ----------------------------------------------------------
                          |               |            |
                       Device         Equipment	     DfcDdd	
						  |			      |		       |
	-----------------------			           --------------------
		|           |                       		   |         |                      
	DbcDevice   DrpDevice                           DbcDevice  DrpDevice 
        |                                              |
     Nhost                                           Nhost




But as you can see in the tree structure we have two paths and only one is correct.The other one contains the Device in path so the Nhost under there is not correct.

My approach has been to go bottom-up.

I check the child list for all the 'Nhost' name and get the indexes for each (2 in my simplified case).

I  the first index and check the parent list and I get the matching DbcDevice. I need to check that vs the "wanted" path and it matches. Then when I reach Device and compare with my seacrch I see this is wrong path.....
As you can see it gets very complicated 

Is there any algorithm for this? Or simply put a better way to do it.

//mikael

Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

searching a tree of objects mike <mikaelpetterson@hotmail.com> - 2015-12-08 10:29 -0800
  Re: searching a tree of objects Eric Douglas <e.d.programmer@gmail.com> - 2015-12-08 10:43 -0800
  Re: searching a tree of objects Martin Gregorie <martin@address-in-sig.invalid> - 2015-12-08 19:22 +0000
  Re: searching a tree of objects mike <mikaelpetterson@hotmail.com> - 2016-01-07 21:59 -0800
    Re: searching a tree of objects Eric Douglas <e.d.programmer@gmail.com> - 2016-01-08 13:35 -0800
    Re: searching a tree of objects Martin Gregorie <martin@address-in-sig.invalid> - 2016-01-08 12:13 +0000

csiph-web