Java 实现飞行地图的邻接列表

Java 实现飞行地图的邻接列表,java,Java,我必须为航空公司服务实现航班地图的邻接列表,我在理解如何实现这一点上遇到了很多困难。我已经有了readFlightMap方法。它读入数据,然后在我的第二个for循环中调用下面的方法,该循环处理邻接列表文件: // Inserts information into the flight map to record the fact that the // adjCity is adjacent to aCity. // Precondition: aCity and adjCity are val

我必须为航空公司服务实现航班地图的邻接列表,我在理解如何实现这一点上遇到了很多困难。我已经有了readFlightMap方法。它读入数据,然后在我的第二个for循环中调用下面的方法,该循环处理邻接列表文件:

// 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)
{

}
我的老师告诉我使用一系列链表来解决这个问题,但这是他在课堂上给我们展示的图片:

LinkedList数组:

在| |中,显示原始城市位置,然后是其调整列表

| 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/>
我已经在谷歌搜索过如何实现这一点,但我没有发现任何有用的东西。他给了我们一个基于ADTList的类,但是它只有简单的东西,比如添加、删除、大小等等,并且它不处理他向我们建议的实现

我迷路了。

你只需要添加


每个城市一份清单。调用insertAdjacent时,将AdjacCity推入城市的列表,反之亦然。

我没有城市类可用的push方法。它在stack类中。我想我只会在从起点到终点的过程中使用它。而不仅仅是为了存储邻接。是这样的吗?private ListArrayBased cityAdj=新建ListArrayBased;public void insertAdjacentCity aCity,City-adjacentcity{cityAdj.add0,aCity;}但是如果存在另一个邻接,我该如何添加到最后一个邻接?每个城市都需要一个邻接列表。要添加到该列表,请调用其add方法。