Home > Back-end >  For help, there is a data structure code, debugging, please god help me
For help, there is a data structure code, debugging, please god help me

Time:10-07

A figure and depth-first traversal
(compiled form are not wrong, perform when there is some garbled! For help,)
#include
using namespace std;

Const int MaxSize=4;
The class MGraph
{
Public:
MGraph (char [], int n, int e);
Void DFSTraverse (int v);

Private:
Char vertex [MaxSize];
Int the arc [MaxSize] [MaxSize];
Int vertexNum arcNum;

};


MGraph: : MGraph (char [], int n, int e)
{
VertexNum=n; ArcNum=e;
int i,j,k;
For (I=0; iVertex=[I] a [I];
for(i=0; i{the for (j=0; JThe arc [I] [j]=0; }
For (k=0; K{
Cin> i> j;
The arc [I] [j]=1;
The arc [j] [I]=1;

}

}


Void MGraph: : DFSTraverse (int v)
{int I, j;
Int visited [MaxSize]={0};
for(i=0; iVisited [I]=0;
Cout<& lt; Vertex [v];
Visited [v]=1;
for(j=0; JIf (arc [v] [j]==1 & amp; & [j]==0) visited DFSTraverse (j);

}

Int main ()
{char q [4]={' a ', 'b', 'c', 'd'};
Int w, I;
/* cout<" Please input data: "& lt; & lt; Endl;
for(i=0; i<4. I++)
{
Cin> w;
Q [I]=w;

} */
MGraph s (q, 4, 4);
Spyware doctor FSTraverse (0);
//return 0;
}

CodePudding user response:

The infinite loop? Visited the array should be public

CodePudding user response:

Sorry, I don't understand, can say a little detail, I am more stupid,, come on

CodePudding user response:

What are your results?
  • Related