为什么我的广度优先遍历打出来是ABCDEFG还没有H
//广度优先遍历 A B D C F G H E
void CMap::breadthFirstTraverse(int nodeIndex){
cout<<mpNodeArray[nodeIndex].mData <<" ";
mpNodeArray[nodeIndex].mvisited =true;
vector<int>curvec;
curvec.push_back(nodeIndex);
breadthFirstTraverseImp(curvec);
}
void CMap::breadthFirstTraverseImp(vector<int> preVec){
int value=0;
vector<int>curvec;//用来保存这一层所有结点
for(int j=0;j<(int)preVec.size() ;j++){//看上一层有多少结点
for(int i=0;i<miCapacity;i++){
getValueFromMatrix(preVec[i],i,value);
if(value!=0){
if(mpNodeArray[i].mvisited ) continue;
else{
cout<<mpNodeArray[i].mData <<" ";
mpNodeArray[i].mvisited =true;
curvec.push_back(i);
}
}
}
}
if(curvec.size() ==0) return;
else breadthFirstTraverseImp(curvec);
}
这是我的代码,求帮忙。