Exemplo n.º 1
0
        /**
         * Returns a list of vertices that are the neighbors of a specified vertex. If the graph is a
         * multigraph vertices may appear more than once in the returned list.
         *
         * <p>
         * The method uses {@link Graph#edgesOf(Object)} to traverse the graph.
         *
         * @param g the graph to look for neighbors in
         * @param vertex the vertex to get the neighbors of
         * @param <V> the graph vertex type
         * @param <E> the graph edge type
         *
         * @return a list of the vertices that are the neighbors of the specified vertex.
         */
        public static List <V> neighborListOf <V, E>(Graph <V, E> g, V vertex)
        {
            List <V> neighbors = new List <V>();

            foreach (E e in g.edgesOf(vertex))
            {
                neighbors.Add(getOppositeVertex(g, e, vertex));
            }

            return(neighbors);
        }