路径搜索,搜索到目标结点的时候算作一条路径.不会有两条一致的路径,但两条不同的路径可以有相同的部分.
同样只是给出了函数定义,贴.
// 2011-08-19-21.14 -- 2011-08-19-21.36 by Golden_Shadow.
// ------------------------------------------------------------------------------------
int graphRepresentAsAdjacentMatrix ::m_numberOfPathBetweenTwoVertexes (
const int startIndex,
const int targetIndex)
{
int count = 0 ;
// Scan each vertex V[startIndex] adjoin to
// Ignore vertex's color, go to find all path from V[startIndex] to V[targetIndex].
for (int i = 0; i < m_row; ++i)
{
if (m_matrix[startIndex][i])
{
if (i == targetIndex)
{
++count ;
}
else
{
count += m_numberOfPathBetweenTwoVertexes(i, targetIndex) ;
}
}
}
return count ;
}
// ------------------------------------------------------------------------------------
// ------------------------------------------------------------------------------------
// Current graph must be acyclic, if not, can't terminate until over flow stack.
// Assume to inspect startIndex and tatgetIndex.
int graphRepresentAsAdjacentMatrix ::numberOfPathBetweenTwoVertexes (
const int startIndex,
const int targetIndex)
{
if (m_currentRow < m_row)
{
std ::cerr << "Fault, there is(are) " << m_row - m_currentRow << " edge(s) has(have) not been imported." << std ::endl ;
return 0 ;
}
return m_numberOfPathBetweenTwoVertexes(startIndex, targetIndex) ;
}
// ------------------------------------------------------------------------------------