📄 graphm.java
字号:
package 旅游行程方案;
public class Graphm { //Graph:Adjaceney matrix
final int VISITED=-1;
final int UNVISITED=-2;
public int[][] martix; //The edge matrix
private int numEdge; //Number of edge
public int[] Mark; //The marx array
public Graphm(int n){ //Constructor
Mark=new int[n];
martix=new int[n][n];
numEdge=0;
}
public int n(){ // Number of vertices
return Mark.length;
}
public int e(){ //Number of edges
return numEdge;
}
public Edgem first(int v){ //Get the first edge for a vertex
for(int i=0;i<Mark.length;i++){
if(martix[v][i]!=0)
return new Edgem(v,i);
}
return null;
}
public Edgem next(Edgem w){ //Get the next edge for a vertex
if(w==null)
return null;
for(int i=w.v2();i<Mark.length;i++){
if(martix[w.v1()][i]!=0)
return new Edgem(w.v1(),i);
}
return null;
}
public boolean isEdge(Edgem w){
if(w==null)
return false;
else
return (martix[w.v1()][w.v2()]!=0);
}
public boolean isEdge(int i,int j){
return (martix[i][j]!=0);
}
public int v1(Edgem w){
return w.v1();
}
public int v2(Edgem w){
return w.v2();
}
public void setEdge(int i,int j,int wt){
if(wt==0)
;
else{
martix[i][j]=wt;
numEdge++;
}
}
public void setEdge(Edgem w,int wt){
if(w!=null)
setEdge(w.v1(),w.v2(),wt);
}
public void delEdge(Edgem w){
if(w!=null)
if(martix[w.v1()][w.v2()]!=0){
martix[w.v1()][w.v2()]=0;
numEdge--;
}
}
public void delEdge(int i,int j){
if(martix[i][j]!=0){
martix[i][j]=0;
numEdge--;
}
}
public int weight(int i,int j){
if(martix[i][j]==0)
return Integer.MAX_VALUE;
else
return martix[i][j];
}
public float weight(Edgem w){
if(martix[w.v1()][w.v2()]==0)
return Integer.MAX_VALUE;
else
return martix[w.v1()][w.v2()];
}
public void setMark(int v,int val){
Mark[v]=val;
}
public int getMark(int v){
return Mark[v];
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -