实现飞行地图的邻接列表

时间:2009-12-07 02:42:08

标签: 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 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)
{

}

我的导师告诉我实施一系列链接列表来解决这个问题,但这是他在课堂上向我们展示的图片:

LinkedLists数组:

在| |,原始城市位置,然后是他们的Adj列表。

| 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的类,但它只有简单的东西,如添加,删除,大小等,它不处理他向我们建议的实现。

我迷路了。

1 个答案:

答案 0 :(得分:0)

您需要的只是添加。

每个城市的一个列表。调用insertAdjacent时,将adjCity推入aCity列表,反之亦然。