Class Node

java.lang.Object
jdg.graph.Node

public class Node extends Object
A class for representing a node of a graph (implemented using adjacency lists)
Author:
Luca Castelli Aleardi (Ecole Polytechnique, feb 2021)
  • Field Details

    • neighbors

      public ArrayList<Node> neighbors
      list of neighbors of the current node
    • label

      public String label
      label of the node: vertex label can differ from vertex index
    • tag

      public int tag
      tag of node: useful for "marking" a node
    • weight

      public double weight
      weight of the node: useful for some applications
    • index

      public int index
      index of a node: an integer value from 0..n-1
    • color

      public Color color
  • Constructor Details

    • Node

      public Node(int index)
    • Node

      public Node(int index, Color color)
    • Node

      public Node(int index, Color color, String label)
  • Method Details

    • addNeighbor

      public void addNeighbor(Node v)
    • removeNeighbor

      public void removeNeighbor(Node v)
    • adjacent

      public boolean adjacent(Node v)
    • isIsolated

      public boolean isIsolated()
      Check whether the current node is isolated (no neighbors)
      Returns:
      true if the current node is isolated (no neighbors)
    • setColor

      public void setColor(int r, int g, int b)
    • neighborsList

      public List<Node> neighborsList()
      Return the list of neighboring nodes
      Returns:
      the list of neighbors of the current node
    • setTag

      public void setTag(int tag)
    • getTag

      public int getTag()
    • setLabel

      public void setLabel(String label)
    • getLabel

      public String getLabel()
    • degree

      public int degree()
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object