JAVA 树中 按最长路径行驶
2008-01-05 18:38:42 来源:WEB开发网 PRivate Vector findRoad(int posX,int posY,int dir){
Vector roadUPVec=null,roadRIGHTVec=null,roadDOWNVec=null,roadLEFTVec=null;
boolean tempUP=false,tempRIGHT=false,tempLEFT=false,tempDOWN=false;
int upNum=0,downNum=0,rightNum=0,leftNum=0,maxNum=0;
if(posY>0 && m_nowMap[posX][posY-1]!=0 && dir!=DIR_UP){
roadUPVec=new Vector();
roadUPVec.addElement(new Integer(posX));
roadUPVec.addElement(new Integer(posY-1));
Vector tempVec=findRoad(posX,posY-1,DIR_DOWN);
if(tempVec!=null){
for(int i=0;i<tempVec.size();i++)
roadUPVec.addElement(tempVec.elementAt(i));
}
}
else
tempUP=false;
if(posX<COLUMN-1 && m_nowMap[posX+1][posY]!=0 && dir!=DIR_RIGHT){
roadRIGHTVec=new Vector();
roadRIGHTVec.addElement(new Integer(posX+1));
roadRIGHTVec.addElement(new Integer(posY));
Vector tempVec=findRoad(posX+1,posY,DIR_LEFT);
if(tempVec!=null){
for(int i=0;i<tempVec.size();i++)
roadRIGHTVec.addElement(tempVec.elementAt(i));
}
}
else
tempRIGHT=false;
if(posY<ROW && m_nowMap[posX][posY+1]!=0 && dir!=DIR_DOWN){
roadDOWNVec=new Vector();
更多精彩
赞助商链接