Skip to content
Snippets Groups Projects
IGraph.java 1.55 KiB
Newer Older
Sondre.Bolland1's avatar
Sondre.Bolland1 committed
package INF102.lab5.graph;

import java.util.Set;

public interface IGraph<V> {

    /**
     * Number of nodes in the graph
     * @return number of nodes in graph
     */
    public int size();

    /**
     * A way to iterate through all vertices of this graph
Sondre.Bolland1's avatar
Sondre.Bolland1 committed
     * @return set of graph nodes
     */
    public Iterable<V> vertices();
Sondre.Bolland1's avatar
Sondre.Bolland1 committed

    /**
     * Add <code>node</code> to graph
     * @param node
     */
    public void addNode(V node);

    /**
     * Remove <code>node</code> from graph
     * @param node
     */
    public void removeNode(V node);

    /**
     * Add edge between node <code>u</code> and <code>v</code>
     * @param u
     * @param v
     * @throws IllegalArgumentException if the nodes given are not in the graph
     */
    public void addEdge(V u, V v);

    /**
     * Remove edge between node <code>u</code> and <code>v</code>
     * @param u
     * @param v
     */
    public void removeEdge(V u, V v);

    /**
     * Checks if the given <code>node</code> is in the graph
Sondre.Bolland1's avatar
Sondre.Bolland1 committed
     * @param node
     * @return true if node is in graph
     */
    public boolean hasNode(V node);

    /**
     * Checks if two given vertices are adjacent
     *
     * @return true if both vertices are in the graph and there is an edge between
     *         them in the graph
Sondre.Bolland1's avatar
Sondre.Bolland1 committed
     */
    public boolean adjacent(V u, V v);
Sondre.Bolland1's avatar
Sondre.Bolland1 committed

    /**
     * Finds all neighbours of node <code>u</code>. 
     * The neighbours of a node is all nodes which it has an edge to.
     * @param node
     * @return list of all neighbours
     */
    public Set<V> neighbours(V node);