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

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

為什么我的廣度優(yōu)先先打印了 8

CMap:

void CMap::BreadthFirstTraverse(int nodeIndex)

{

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

m_pNodeArray[nodeIndex].m_bIsVisited = true;

vector<int> curVec;

curVec.push_back(nodeIndex);


BreadthFirstTraverseImpl(curVec);

}


void CMap::BreadthFirstTraverseImpl(vector<int> preVec)

{

int value = 0;

vector<int> curVec;


for (int j = 0; j < (int)preVec.size(); j++)

{

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

{

GetValueFromMatrix(preVec[j], i, value);

if (value != 0)

{

if (m_pNodeArray[i].m_bIsVisited)

{

continue;

}

else

{

cout << m_pNodeArray[i].m_cData <<" ";

m_pNodeArray[i].m_bIsVisited = true;

curVec.push_back(i);

}

}

}


if (curVec.size() == 0)

{

return;

}

else

{

BreadthFirstTraverseImpl(curVec);

}

}

}



bool CMap::GetValueFromMatrix(int row, int col, int &val)

{

if (row < 0 || row >= m_iCapacity)

{

return false;

}

if (col < 0 || col >= m_iCapacity)

{

return false;

}

val = m_pMatrix[row*m_iCapacity+col];

return true;?

}

Main:

#include <iostream>

#include <stdlib.h>

#include "CMap.h"

using namespace std;

/*

1

2 3

? 4? 5? 6? 7

? ? 8


1 2 3 4 5 6 7 8

1 1 1

2 1 1 1

3 1 1 1

4 1 1

5 1 1

6 1 1

7 1 1

8 1 1

*/


int main()

{

CMap *map = new CMap(8);


MapNode node1;

node1.m_cData = '1';

MapNode node2;

node2.m_cData = '2';

MapNode node3;

node3.m_cData = '3';

MapNode node4;

node4.m_cData = '4';

MapNode node5;

node5.m_cData = '5';

MapNode node6;

node6.m_cData = '6';

MapNode node7;

node7.m_cData = '7';

MapNode node8;

node8.m_cData = '8';


map->AddNode(&node1);

map->AddNode(&node2);

map->AddNode(&node3);

map->AddNode(&node4);

map->AddNode(&node5);

map->AddNode(&node6);

map->AddNode(&node7);

map->AddNode(&node8);


map->SetValueToMatrixForUndirectedGraph(0, 1);

map->SetValueToMatrixForUndirectedGraph(0, 2);

map->SetValueToMatrixForUndirectedGraph(1, 3);

map->SetValueToMatrixForUndirectedGraph(1, 4);

map->SetValueToMatrixForUndirectedGraph(2, 5);

map->SetValueToMatrixForUndirectedGraph(2, 6);

map->SetValueToMatrixForUndirectedGraph(3, 7);

map->SetValueToMatrixForUndirectedGraph(4, 7);

map->SetValueToMatrixForUndirectedGraph(5, 6);


map->PrintMatrix();


cout << endl;


map->BreadthFirstTraverse(0);


delete map;

map = NULL;

system("pause");

return 0;

}https://img1.sycdn.imooc.com//5c8fa0f40001554304660292.jpg

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

正在回答

2 回答

這個(gè)圖https://img1.sycdn.imooc.com//5ca3321d0001448c14680766.jpg

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

我用了自己的類定義、成員函數(shù)同時(shí)用了你的主程序,得到的結(jié)果如下。你的類定義以及成員函數(shù)的書寫是不是和james的一模一樣?老師的代碼是有一點(diǎn)問題的,他漏了一個(gè)continue,在breadthFirstTraverseImpl函數(shù)里面,兩個(gè)for循環(huán)當(dāng)中,"if(value==0)continue;"他忘了寫,對照深度遍歷的函數(shù)相信你很容易理解。

spacer.gif

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

舉報(bào)

0/150
提交
取消

為什么我的廣度優(yōu)先先打印了 8

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

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

幫助反饋 APP下載

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

公眾號(hào)

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