It's not a secret anymore!
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


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: 20078
    
  30

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


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

Joined: Oct 13, 2005
Posts: 43970
    
  33
Welcome to the Ranch

That isn't called a linked list, more likely a "graph".
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Iterating over a (kind of) linked list
 
It's not a secret anymore!