主题:帮忙看一下这个函数调用怎么出错了
void CGraph::Dijkstra(ID SourceNum)
{
vector<UINT>Distant(m_uiVertexNum, UINT(INFUINT));//记录到每个节点的最短路径
vector<bool>s(m_uiVertexNum, bool(0));//使用布尔矩阵来记录节点i是否已经进入集合S
vector<ID>Link(m_uiVertexNum, ID(0));//记录路径
Distant[SourceNum] = 0;
s[SourceNum] = 1;
UINT i;
list<ID>::iterator iend;//声明一个迭代器
iend= m_vVertex[SourceNum].m_lAdjVertex.end();
for(it = m_vVertex[SourceNum].m_lAdjVertex.begin(); it !=iend; it++)
{
link_temp = m_mVertexIdPairEdgeIdMap[make_pair(SourceNum, *it)];
Distant[*it] = m_vEdge[link_temp].GetWeight();
Link[*it] = SourceNum;
}
UINT weight_temp = INFUINT;
ID v_temp = SourceNum;
//依次将每个节点放入矩阵S中
//while(s[v_SinkId] != 1)
do
{
//找出即将进入集合S的节点
for(i = 0; i < m_uiVertexNum; i++)
{
if((s[i] == 0) && (Distant[i] < weight_temp))
{
v_temp = i;
weight_temp = Distant[i];
}
}
s[v_temp] = 1;
if(v_temp == SourceNum)
{
break;
}
}
//更新最小权值
[color=808000]Update(v_temp);[/color]
while(!s.empty());
//更新m_mShortestDistance的值
for(i = 0; i < m_uiVertexNum; i++)
{
m_vVertex[SourceNum].m_mShortestDistance[i] = Distant[i];
}
cout<<endl;
}
void CGraph::Update(ID v_temp)
{
for(it = m_vVertex[v_temp].m_lAdjVertex.begin(); it != m_vVertex[v_temp].m_lAdjVertex.end(); it++)
{
link_temp = m_mVertexIdPairEdgeIdMap[make_pair(v_temp, *it)];
if((s[*it] == 0) && (Distant[*it] > Distant[v_temp] + m_vEdge[link_temp].GetWeight()))
{
Distant[*it] = Distant[v_temp] + m_vEdge[link_temp].GetWeight();
Link[*it] = v_temp;
}
}
}
我编译后一直提示 identifier 'Update' 也就是我在算法的函数里调用Update函数说未定义,为啥呢。头文件已经在public里写了void Update(ID v_temp)
{
vector<UINT>Distant(m_uiVertexNum, UINT(INFUINT));//记录到每个节点的最短路径
vector<bool>s(m_uiVertexNum, bool(0));//使用布尔矩阵来记录节点i是否已经进入集合S
vector<ID>Link(m_uiVertexNum, ID(0));//记录路径
Distant[SourceNum] = 0;
s[SourceNum] = 1;
UINT i;
list<ID>::iterator iend;//声明一个迭代器
iend= m_vVertex[SourceNum].m_lAdjVertex.end();
for(it = m_vVertex[SourceNum].m_lAdjVertex.begin(); it !=iend; it++)
{
link_temp = m_mVertexIdPairEdgeIdMap[make_pair(SourceNum, *it)];
Distant[*it] = m_vEdge[link_temp].GetWeight();
Link[*it] = SourceNum;
}
UINT weight_temp = INFUINT;
ID v_temp = SourceNum;
//依次将每个节点放入矩阵S中
//while(s[v_SinkId] != 1)
do
{
//找出即将进入集合S的节点
for(i = 0; i < m_uiVertexNum; i++)
{
if((s[i] == 0) && (Distant[i] < weight_temp))
{
v_temp = i;
weight_temp = Distant[i];
}
}
s[v_temp] = 1;
if(v_temp == SourceNum)
{
break;
}
}
//更新最小权值
[color=808000]Update(v_temp);[/color]
while(!s.empty());
//更新m_mShortestDistance的值
for(i = 0; i < m_uiVertexNum; i++)
{
m_vVertex[SourceNum].m_mShortestDistance[i] = Distant[i];
}
cout<<endl;
}
void CGraph::Update(ID v_temp)
{
for(it = m_vVertex[v_temp].m_lAdjVertex.begin(); it != m_vVertex[v_temp].m_lAdjVertex.end(); it++)
{
link_temp = m_mVertexIdPairEdgeIdMap[make_pair(v_temp, *it)];
if((s[*it] == 0) && (Distant[*it] > Distant[v_temp] + m_vEdge[link_temp].GetWeight()))
{
Distant[*it] = Distant[v_temp] + m_vEdge[link_temp].GetWeight();
Link[*it] = v_temp;
}
}
}
我编译后一直提示 identifier 'Update' 也就是我在算法的函数里调用Update函数说未定义,为啥呢。头文件已经在public里写了void Update(ID v_temp)