Class VertexList

All Implemented Interfaces:
Iterable<Integer>
Direct Known Subclasses:
Walk

public class VertexList extends VertexCollection
A list of vertices of a graph. A vertex can appear multiple times.
Author:
Cristian Frăsinaru
See Also:
  • Constructor Details

    • VertexList

      public VertexList(Graph graph)
    • VertexList

      public VertexList(Graph graph, int initialCapacity)
    • VertexList

      public VertexList(Graph graph, int[] vertices)
  • Method Details

    • remove

      public boolean remove(int v)
      Description copied from class: VertexCollection
      Removes a vertex from the collection.
      Overrides:
      remove in class VertexCollection
      Parameters:
      v - a vertex number
      Returns:
      true, if the collection changed as a result of this call
    • removeFromPos

      public void removeFromPos(int pos)
      Overrides:
      removeFromPos in class VertexCollection
    • add

      public boolean add(int v)
      Description copied from class: VertexCollection
      Adds the vertex in the collection.
      Overrides:
      add in class VertexCollection
      Parameters:
      v - a vertex number
      Returns:
      true, if the collection changed as a result of this call
    • addAll

      public void addAll(int... vertices)
      Overrides:
      addAll in class VertexCollection
      Parameters:
      vertices - an array of vertex numbers.
    • indexOf

      public int indexOf(int v)
      Overrides:
      indexOf in class VertexCollection
      Parameters:
      v - a vertex number
      Returns:
      the position of the first appearance of v in the array, or -1 if v does not belong to it
    • indexOf

      public int indexOf(int v, int startPos)
      Overrides:
      indexOf in class VertexCollection
      Parameters:
      v - a vertex number
      startPos - the start position
      Returns:
      the position of the first appearance of v in the array, starting with the given position (inclusive), or -1 if v does not belong to it
    • get

      public int get(int pos)
      Returns the vertex at the specified position in this list.
      Parameters:
      pos - a position in the list
      Returns:
      the vertex at the specified position
    • set

      public void set(int pos, int v)
      Replaces the vertex at the specified position in this list with the specified vertex.
      Parameters:
      pos - position of the vertex to replace.
      v - a vertex number.
    • insert

      public void insert(int pos, int v)
      Inserts a vertex at the specified position in this list.
      Parameters:
      pos - position where the vertex must be inserted.
      v - a vertex number.
    • union

      public VertexList union(int... other)
      Parameters:
      other - an array of vertex numbers.
      Returns:
      a new list containing vertices belonging to this list or the other array.
    • union

      public VertexList union(VertexList other)
      Parameters:
      other - a list of vertex numbers.
      Returns:
      a new list containing vertices belonging to this list or the other.