为什么打印矩阵结果和老师的不一样呢?
为什么打印矩阵结果和老师的不一样呢?
打印函数是这个:
void CMap::printMatrix() { for(int i=0;i<m_iCapacity;i++) { for(int k=0;k<m_iCapacity;k++) { cout<<m_pMatrix[i*m_iCapacity+k]<<" "; } cout<<endl; } }
主函数是这个:
int main(void) { CMap *pMap=new CMap(8); Node *pNodeA=new Node('A'); Node *pNodeB=new Node('B'); Node *pNodeC=new Node('C'); Node *pNodeD=new Node('D'); Node *pNodeE=new Node('E'); Node *pNodeF=new Node('F'); Node *pNodeG=new Node('G'); Node *pNodeH=new Node('H'); pMap->addNode(pNodeA); pMap->addNode(pNodeB); pMap->addNode(pNodeC); pMap->addNode(pNodeD); pMap->addNode(pNodeE); pMap->addNode(pNodeF); pMap->addNode(pNodeG); pMap->addNode(pNodeH); pMap->setValueToMatrixForUndirectedGraph(0,1); pMap->setValueToMatrixForUndirectedGraph(0,3); pMap->setValueToMatrixForUndirectedGraph(1,2); pMap->setValueToMatrixForUndirectedGraph(1,5); pMap->setValueToMatrixForUndirectedGraph(2,4); pMap->setValueToMatrixForUndirectedGraph(4,5); pMap->setValueToMatrixForUndirectedGraph(3,6); pMap->setValueToMatrixForUndirectedGraph(3,7); pMap->setValueToMatrixForUndirectedGraph(6,7); pMap->printMatrix(); cout<<endl; pMap->depthFirstTraverse(0); cout<<endl; pMap->resetNode(); pMap->breadthFirstTraverse(0); system("pause"); return 0; }