This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Iterating over a (kind of) linked list Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Iterating over a (kind of) linked list" Watch "Iterating over a (kind of) linked list" New topic
Author

Iterating over a (kind of) linked list

John Tupple
Greenhorn

Joined: Jul 28, 2010
Posts: 1
Hi Everyone,

I am facing a small challenge that I'm hoping someone can help with. I have built a model of a city map that contains cities that each contain a list of other cities they are connected to, like this:



I am using the map to calculate routes that contain four, five or more cities. I am concerned that my method is not very efficient, it involves iterating over multiple arrays and 'moving' backwards and forwards over the map. My questions is whether there is an efficient way to calculate the route through 'n' cities, given 'n' can change.

Thanks in advance.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19655
    
  18

Look up the traveling salesman problem. And no, it's not going to be efficient.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38045
    
  22
Welcome to the Ranch

That isn't called a linked list, more likely a "graph".
 
wood burning stoves
 
subject: Iterating over a (kind of) linked list
 
Similar Threads
removing duplicate elements
Iterating over map in jsp using jstl
Different Colour for different group of overlapping circles.
Records in Arraylist
Toughest Questions for Oracle JSP Servlet (SCWCD 5.0) Doubts