tags:

views:

63

answers:

1

I have to implement a flight map's adjacency list for a airline service and I'm having a lot of trouble understanding how to implement this. I have the readFlightMap method already. Which reads in the data and then calls upon the method below in my 2nd for loop which handles the adjacency list file:

// Inserts information into the flight map to record the fact that the
// adjCity is adjacent to aCity.
// Precondition: aCity and adjCity are valid cities that are served
// by the airline.
// Postcondition: The map will have changed to record the given information

public void insertAdjacent(City aCity, City adjCity)
{

}

My instructor told me to implement a array of linked lists to solve this problem, but this is the picture he showed us in class:

An Array of LinkedLists:

In the | |, the original city positions, then followed by their Adj list.

| Q | -> X<br/>
| X | -> No Adj<br/>
| R | -> X<br/>
| P | ->R ->W<br/>
| W | ->S<br/>
| S | ->T<br/>
| T | ->W<br/>
| Y | ->R ->Z<br/>
| Z | ->No Adj<br/>

I've searched all over google about how to implement this, but I have not discovered anything that helps. He gave us a ADTList based class, but it only has simple things like add, remove, size, etc and it does not handle the implementation that he suggested to us.

I'm lost.

A: 

All you need is add.

One list for each city. When insertAdjacent is called, push adjCity into aCity's list, and vice versa.

Anon.
I don't have a push method available to the City class. It's in the stack class. I assumed I would only use that when I'm actually going from the origin to the destination. Not for this purpose of just storing the adjacencies. Would it be something like this? private ListArrayBased cityAdj = new ListArrayBased(); public void insertAdjacent(City aCity, City adjCity) {cityAdj.add(0, aCity); } But then how do I add to that last incase there's another adjacency?
javaRancher2009
Each city will need to have a list of adjacents. To add to that list, call its `add` method.
Anon.