?? edge.java
字號:
package dsa.adt;
public class Edge {
public static final int NORMAL = 0;
public static final int MST = 1; //MST邊
public static final int CRITICAL = 2;//關鍵路徑中的邊
private int weight; //權值
private Object info; //邊的信息
private Node edgePosition; //邊在邊表中的位置
private Node firstVexPosition; //邊的第一頂點與第二頂點
private Node secondVexPosition; //在頂點表中的位置
private Node edgeFirstPosition; //邊在第一(二)頂點的鄰接(逆鄰接)邊表中的位置
private Node egdeSecondPosition;//在無向圖中就是在兩個頂點的鄰接表中的位置
private int type; //邊的類型
private int graphType; //所在圖的類型
//構造方法:在圖G中引入一條新邊,其頂點為u、v
public Edge(Graph g, Vertex u, Vertex v, Object info){
this(g,u,v,info,1);
}
public Edge(Graph g, Vertex u, Vertex v, Object info, int weight) {
this.info = info;
this.weight = weight;
edgePosition = g.insert(this);
firstVexPosition = u.getVexPosition();
secondVexPosition = v.getVexPosition();
type = Edge.NORMAL;
graphType = g.getType();
if (graphType==Graph.UndirectedGraph){
//如果是無向圖,邊應當加入其兩個頂點的鄰接邊表
edgeFirstPosition = u.getAdjacentEdges().insertLast(this);
egdeSecondPosition = v.getAdjacentEdges().insertLast(this);
}else {
//如果是有向圖,邊加入起始點的鄰接邊表,終止點的逆鄰接邊表
edgeFirstPosition = u.getAdjacentEdges().insertLast(this);
egdeSecondPosition = v.getReAdjacentEdges().insertLast(this);
}
}
//get&set methods
public Object getInfo(){ return info;}
public void setInfo(Object obj){ this.info = info;}
public int getWeight(){ return weight;}
public void setWeight(int weight){ this.weight = weight;}
public Vertex getFirstVex(){ return (Vertex)firstVexPosition.getData();}
public Vertex getSecondVex(){ return (Vertex)secondVexPosition.getData();}
public Node getFirstVexPosition(){ return firstVexPosition;}
public Node getSecondVexPosition(){ return secondVexPosition;}
public Node getEdgeFirstPosition(){ return edgeFirstPosition;}
public Node getEdgeSecondPosition(){ return egdeSecondPosition;}
public Node getEdgePosition(){ return edgePosition;}
//與邊的類型相關的方法
public void setToMST(){ type = Edge.MST;}
public void setToCritical(){ type = Edge.CRITICAL;}
public void resetType(){ type = Edge.NORMAL;}
public boolean isMSTEdge(){ return type==Edge.MST;}
public boolean isCritical(){ return type==Edge.CRITICAL;}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -