第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

普利姆算法的輸出有問(wèn)題,麻煩大家看看是哪里錯(cuò)了,謝謝!

https://img1.sycdn.imooc.com//5b4dac06000180b306770442.jpg

void CMap::primTree(int nodeIndex)

{

int value=0;

int edgeCount=0;?

vector<int> nodeVec;

vector<Edge> edgeVec;//備選邊的集合?

cout<<m_pNodeArray[nodeIndex].m_cData<<endl;

nodeVec.push_back(nodeIndex);

m_pNodeArray[nodeIndex].m_bIsVisited = true;

//

while(edgeCount<m_iCapacity-1)

{

int temp=nodeVec.back();//取出最尾部的元素

for(int i=0;i<m_iCapacity;i++)

{

getValueFromMatrix(temp,i,value);

if(value!=0)

{

if(m_pNodeArray[i].m_bIsVisited)

{

continue;

}

else

{

Edge edge(temp,i,value);

edgeVec.push_back(edge);

}

}

} //for循環(huán)做完就將與temp相關(guān)的所有邊放進(jìn)edgeVec中?


//從可選邊集合中找出最小的邊?

int edgeIndex = getMinEdge(edgeVec);?

edgeVec[edgeIndex].m_bSelected = true;

cout<<edgeVec[edgeIndex].m_iNodeIndexA<<"--"<<edgeVec[edgeIndex].m_iNodeIndexB<<"? ";

cout<<edgeVec[edgeIndex].m_iWeightValue<<endl;

m_pEdge[edgeCount] = edgeVec[edgeIndex];

edgeCount++;

int nextNodeIndex = edgeVec[edgeIndex].m_iNodeIndexB;

nodeVec.push_back(nextNodeIndex);

m_pNodeArray[nextNodeIndex].m_bIsVisited=true;

cout<<m_pNodeArray[nextNodeIndex].m_cData<<endl;

}

}

int CMap::getMinEdge(vector<Edge>edgeVec)

{

int minWeight=0;

int edgeIndex=0;

int i=0;

for(;i<edgeVec.size();i++)

{

if(!edgeVec[i].m_bSelected)

{

minWeight = edgeVec[i].m_iWeightValue;

edgeIndex =i;

break;?

}

}

if(minWeight==0)//當(dāng)前edgeVec中的所有邊已經(jīng)被訪問(wèn)?

{

return -1;

}

for(;i<edgeVec.size();i++)

{

if(edgeVec[i].m_bSelected)

{

continue;

}

else

{

if(minWeight>edgeVec[i].m_iWeightValue)

{

minWeight=edgeVec[i].m_iWeightValue;

? ? edgeIndex = i;

}

}

}

return edgeIndex;

}


正在回答

1 回答


http://img1.sycdn.imooc.com//5b535ce30001d15406310142.jpg
這里應(yīng)該是把nextnodeindex放進(jìn)去 函數(shù)是nodevc.back(nextnodeindex) 你手誤了 那樣是放不進(jìn)去的 這樣的話 下一次還從A找 所以就錯(cuò)了

1 回復(fù) 有任何疑惑可以回復(fù)我~
#1

wonder_skye 提問(wèn)者

程序是正確的,之后發(fā)現(xiàn)錯(cuò)誤是在main函數(shù)中,在對(duì)圖進(jìn)行賦值的時(shí)候采用的了對(duì)有向圖賦值的方法,所以導(dǎo)致結(jié)果錯(cuò)誤。 還是謝謝您的回答!
2018-07-26 回復(fù) 有任何疑惑可以回復(fù)我~
#2

wonder_skye 提問(wèn)者

程序是正確的,之后發(fā)現(xiàn)錯(cuò)誤是在main函數(shù)中,在對(duì)圖進(jìn)行賦值的時(shí)候采用的了對(duì)有向圖賦值的方法,所以導(dǎo)致結(jié)果錯(cuò)誤。 還是謝謝您的回答!
2018-07-26 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

普利姆算法的輸出有問(wèn)題,麻煩大家看看是哪里錯(cuò)了,謝謝!

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)