Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. import java.util.ArrayList;
  2. //Represents vertices of the graph
  3. public class Vertex implements Comparable<Vertex>{
  4.    
  5.     private ArrayList<Edge> outGoingEdges=new ArrayList<>();//out going edges from the node
  6.     private String val;//node value
  7.     private boolean visited; //visited or not
  8.     private Double distance = Double.POSITIVE_INFINITY;//initial distances infinity
  9.     private Vertex prev=null;//previous node
  10.    
  11.     public Vertex getPrev() {
  12.         return prev;
  13.     }
  14.  
  15.     public void setPrev(Vertex prev) {
  16.         this.prev = prev;
  17.     }
  18.  
  19.     boolean isStart;
  20.    
  21.     public Vertex(String val){
  22.         this.val=val;
  23.         this.isStart=false;
  24.     }
  25.    
  26.     public void addEdge(Vertex dest,double weight){
  27.         this.outGoingEdges.add(new Edge(dest, weight));
  28.        
  29.     }
  30.    
  31. //getter and setters
  32.  
  33.     public ArrayList<Edge> getOutGoingEdges() {
  34.         return outGoingEdges;
  35.     }
  36.  
  37.  
  38.     public void setOutGoingEdges(ArrayList<Edge> outGoingEdges) {
  39.         this.outGoingEdges = outGoingEdges;
  40.     }
  41.     public boolean isVisited() {
  42.         return visited;
  43.     }
  44.  
  45.  
  46.     public String getVal() {
  47.         return val;
  48.     }
  49.  
  50.     public void setVal(String val) {
  51.         this.val = val;
  52.     }
  53.  
  54.     public void setVisited(boolean visited) {
  55.         this.visited = visited;
  56.     }
  57.  
  58.     public Double getDistance() {
  59.         return distance;
  60.     }
  61.  
  62.     public void setDistance(Double distance) {
  63.         this.distance = distance;
  64.     }
  65.  
  66.     @Override
  67.     public int compareTo(Vertex o) {
  68.         return this.distance.compareTo(o.getDistance());
  69.     }
  70.    
  71.    
  72. }