Implementing an Adjacency List for a Flight Map

Discussion in 'OT Technology' started by SPACECATAZ, Dec 7, 2009.

  1. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0
    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:

    [​IMG]

    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. :squint:
     
  2. SPACECATAZ

    SPACECATAZ New Member

    Joined:
    Dec 22, 2006
    Messages:
    2,502
    Likes Received:
    0
    This is my city class:

    Code:
    public class City {
    
        private String name;
        private boolean visited;
        
        // Initializes a City with cityName and marks the City
        // as unvisited.
        public City(String cityName) {
            this.name = cityName;
            this.visited = false;
        }
        
        // Returns the name of the City
        public String getName() {
            return name;
        }
        
        // Returns true if the City has been visited
        // and false otherwise
        public boolean isVisited() {
            return (visited == true);
        }
        
        // Marks the city as having been visited
        public void visit() {
            visited = true;
        }
        
        // Clears the visited mark so the city will
        // me marked as unvisited.
        public void clear() {
            visited = false;
        }
    
        // Overridden equals method determines if the
        // current City name is equal to obj
        public boolean equals(Object obj) {
            return (name.equals(obj));
        }
        
        // Overrridden toString method returns the
        // name of the City
        public String toString() {
            return name;
        }
    
    }
    
     

Share This Page