Java Reference
In-Depth Information
/ ** Settheweightforanedge * /
publicvoidsetEdge(inti,intj,intweight){
assertweight!=0:"Maynotsetweightto0";
EdgecurrEdge=newEdge(j,weight);
if(isEdge(i,j)){//Edgealreadyexistsingraph
vertex[i].remove();
vertex[i].insert(currEdge);
}
else{//Keepneighborssortedbyvertexindex
numEdge++;
for(vertex[i].moveToStart();
vertex[i].currPos()<vertex[i].length();
vertex[i].next())
if(vertex[i].getValue().vertex()>j)break;
vertex[i].insert(currEdge);
}
}
/ ** Deleteanedge * /
publicvoiddelEdge(inti,intj)
{if(isEdge(i,j)){vertex[i].remove();numEdge--;}}
/ ** Determineifanedgeisinthegraph * /
publicbooleanisEdge(intv,intw){
Edgeit=vertex[v].getValue();
//Checkifjisthecurrentneighborinthelist
if((it!=null)&&(it.vertex()==w))returntrue;
for(vertex[v].moveToStart();
vertex[v].currPos()<vertex[v].length();
vertex[v].next()) //Checkwholelist
if(vertex[v].getValue().vertex()==w)returntrue;
returnfalse;
}
/ ** @returnanedge'sweight * /
publicintweight(inti,intj){
if(isEdge(i,j))returnvertex[i].getValue().weight();
return0;
}
/ ** Set/Getthemarkvalueforavertex * /
publicvoidsetMark(intv,intval){Mark[v]=val;}
publicintgetMark(intv){returnMark[v];}
}
Figure11.7 (continued)
Search WWH ::




Custom Search