aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 19556
    
  16

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: 36579
    
  16
Welcome to the Ranch

That isn't called a linked list, more likely a "graph".
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Iterating over a (kind of) linked list
 
Similar Threads
Different Colour for different group of overlapping circles.
removing duplicate elements
Iterating over map in jsp using jstl
Records in Arraylist
Toughest Questions for Oracle JSP Servlet (SCWCD 5.0) Doubts