Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

algorithm problem with recursion

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an algorithm problem with recursion:

i have a route from A to D and it looks like this



the alphabet in the above list is an object of a class, lets call that class Nodes

each of this Nodes object they have some attributes... these are of type set..

the first set will store a bunch of other Nodes (these represent the current nodes neighbour)
the second set will store a bunch of tracks (Integer object representing what tracks the current nodes belong to)

(... bare with me here... )

so now i write up some code that initialise all the nodes... and here is the output...



and here is the code: (i removed the System.out... to shorten the code..)



what i want to do is to come up with some recursive algorithm so that it would print out something like this...

so i've come up with a pseudo code...


i've also come up with an actuall code but for some reason it'll only prints out the first step...

the code for this to follow...
 
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Given the data shouldn't your output be:



Or are there some other rules here?
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Here is the output from again



here A has 3 next neighbours that is B Z and E
and A has a/belongs to 3 tracks 1, 2, and 3

and we are given a route from A - B - C - D

so from A we are only interested with B (dont care about Z & E)
then we look at the what track A has and we also look at what track B has...
in this case track 1 is a match...

so then we do a next matching

B neighbour is A and C. A is already been visited... so we only care about C... see for macthing line and between B and C which is 1... and so on...
 
It's a tiny ad. At least, that's what she said.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic