C++;递归函数在图中的实现 我试图在C++程序中实现一个算法,它首先要遍历图中的每一个边。在图中,我从输出端口开始搜索,然后向输入端口前进。如果我发现我的一个节点的outdegree大于1,我将调用一个递归函数,该函数遍历outdegree,并应为我提供其中最大的值。不幸的是,我的代码没有按预期工作

C++;递归函数在图中的实现 我试图在C++程序中实现一个算法,它首先要遍历图中的每一个边。在图中,我从输出端口开始搜索,然后向输入端口前进。如果我发现我的一个节点的outdegree大于1,我将调用一个递归函数,该函数遍历outdegree,并应为我提供其中最大的值。不幸的是,我的代码没有按预期工作,c++,recursion,graph-theory,C++,Recursion,Graph Theory,代码如下所示- if(graph.gate_list.at(check).OutEdgeCount()>1) //Suppose a node has more than one output edge, then we need to find the maximum delay for that node before moving upwards { p_edge_check=p_edge; p_edge= graph.gate_list.at(check).fi

代码如下所示-

if(graph.gate_list.at(check).OutEdgeCount()>1) //Suppose a node has more than one output   edge, then we need to find the maximum delay for that node before moving upwards
{
    p_edge_check=p_edge;
    p_edge= graph.gate_list.at(check).first_out_edge;
    stack<Edge<delay_type, error_type>* > keep_edge, keep_edge1;
    for(int index=0; index<11; index++)
    {
        for(int j=0; j< 10; j++)
        {
            gate_stack_temp.push_back(temp2);
        }
        while(!keep_edge1.empty())
        {
            p_edge= keep_edge1.top();
            p_edge->active=true;
            keep_edge1.pop();
        }
        delay_gate[path_index][index] = /*delay_gate[path_index][index] +*/ Recursion_Loop(graph,gate_stack_temp, p_edge, keep_edge, keep_edge1, delay_temp, index);

        gate_stack[index][path_index].assign(gate_stack_temp[0].front(), gate_stack_temp[0].back());

        gate_stack_temp.clear();
        p_edge=p_edge_check;
        for(int i=0; i<delay_temp.size(); i++) 
        {
            delay_temp[i]=0;
        }
    }
    while(!keep_edge1.empty())
    {
        keep_edge1.pop();
    }
    p_edge=p_edge_check;
}
if(graph.gate_list.at(check).OutEdgeCount()>1)//假设一个节点有多个输出边,那么我们需要在向上移动之前找到该节点的最大延迟
{
p_边检查=p_边;
p_edge=graph.gate_list.at(check).first_out_edge;
堆叠保持边缘,保持边缘1;
对于(int index=0;indexactive=true;
保持边缘1.pop();
}
延迟门[路径索引][索引]=/*延迟门[路径索引][索引]+*/递归循环(图、门堆栈温度、p_边、保持边、保持边1、延迟温度、索引);
门栈[index][path\u index].assign(门栈[0].front(),门栈[0].back());
闸门堆叠温度清除();
p_边=p_边检查;
对于(inti=0;ihead_index).OutEdgeCount()>0)
{
p_-edge=graph.gate_list.at(p_-edge->head_-index);
if(FindPathLoop2(门\堆栈\温度,p\边缘->头\索引,温度\路径))
{
p_edge=p_edge->same_tail_next;
if(p_边==NULL)
{
转到第1点;
}
/*if(graph.gate_list.at(p_edge->head_index).OutEdgeCount()<0)
p_edge_temp=p_edge->same_tail_next;
如果(p_边缘_温度==NULL)
返回图.gate\u list.at(p\u edge->head\u index).delay.at(index)+p\u edge->delay;
否则p_边缘=p_边缘温度;
if(!p_edge->active)返回graph.gate_list.at(p_edge->head_index.delay.at(index)+p_edge->delay;
*/
如果(!FindPathLoop1(保持边缘1,p边缘))
{
保持边缘1.推动(边缘);
}
p_边缘->活动=假;
delay_temp[temp_path]=delay_temp[temp_path]+p_edge->delay+graph.gate_list.at(p_edge->tail_index).delay.at(index)+递归_循环(graph,gate_stack_temp,p_edge,keep_edge,keep_edge1,delay_temp,index);
p_edge=保持_edge.top();
保持_edge.pop();
门栈温度[temp\u path]。向后推(p\u边->头索引);
}
其他的
{
如果(!FindPathLoop1(保持边缘1,p边缘))
{
保持边缘1.推动(边缘);
}
p_边缘->活动=假;
if(graph.gate\u list.at(p\u edge->head\u index).OutEdgeCount()==0)
{
if(FindPathLoop2(门\堆栈\温度,p\边缘->头\索引,温度\路径))
{
门栈温度[temp\u path]。向后推(p\u边->头索引);
}
返回(p_edge->delay+graph.gate_list.at(p_edge->head_index.delay.at(index));
}
其他的
{
返回0;
}
}
p_edge=p_edge->same_tail_next;
if(延时温度[temp\U path]>延时温度[0])
{
延迟温度[0]=延迟温度[temp\u path];
而(!gate\u stack\u temp[0].empty())
{
门堆栈温度[0]。弹出返回();
}
而(!gate\u stack\u temp[temp\u path].empty())
{
门堆栈温度[0]。推回(门堆栈温度[temp\u path]。返回());
gate_stack_temp[temp_path].pop_back();
}
}
否则如果(临时路径!=0)
{
而(!gate\u stack\u temp[temp\u path].empty())
{
gate_stack_temp[temp_path].pop_back();
}
}
temp_path++;
}
/*if(延迟温度[0]>延迟温度[temp路径])
{
延迟温度[0]=延迟温度[temp\u path];
而(!gate\u stack\u temp[0].empty())
门堆栈温度[0]。弹出返回();
而(!gate\u stack\u temp[temp\u path].empty())
{
门堆栈温度[0]。推回(门堆栈温度[temp\u path]。返回());
gate_stack_temp[temp_path].pop_back();
}
}*/
第1点: 返回延迟_temp[0]; }

<>因为我是C++新手(和以前只有C基本知识的图论),我相信我的方法可能阻碍输出。如果有人能看看这段代码,我会非常高兴。我已经做了几个星期没有任何结果,因此现在不得不寻求帮助

编辑:以下是已调用的FindPathLoop函数-

    bool FindPathLoop(vector<vector<vector<int> > > &gate_stack, int gate_index, int path_index)
    {
        vector<int> temp;

        while(!gate_stack[0][path_index].empty())
        {
            if(gate_index == gate_stack[0][path_index].back())
            {
                while(!temp.empty())
                {   
                    gate_stack[0][path_index].push_back(temp.back());
                    temp.pop_back();
                }
                return true;
            }
            temp.push_back(gate_stack[0][path_index].back());
            gate_stack[0][path_index].pop_back();
        }

        while(!temp.empty())
        {
            gate_stack[0][path_index].push_back(temp.back());
            temp.pop_back();
        }
        return false;
    }

     bool FindPathLoop1(stack<Edge<delay_type, error_type>* > &keep_edge, Edge<delay_type, error_type> *p_edge)
     {
           stack<Edge<delay_type, error_type>* > temp;
           while(!keep_edge.empty())
           {
               if(p_edge == keep_edge.top())
               {
                   while(!temp.empty())
                   {
                       keep_edge.push(temp.top());
                       temp.pop();
                   }
                   return true;
               }
               temp.push(keep_edge.top());
               keep_edge.pop();
           }
           while(!temp.empty())
           {
               keep_edge.push(temp.top());
               temp.pop();
           }
           return false;
       }

     bool FindPathLoop2(vector<vector<int> > &gate_stack, int gate_index, int path_index)
     {
        vector<int> temp;

        while(!gate_stack[path_index].empty())
        {
            if(gate_index == gate_stack[path_index].back())
            {
                while(!temp.empty())
                {
                    gate_stack[path_index].push_back(temp.back());
                    temp.pop_back();
                }
                return true;
            }
            temp.push_back(gate_stack[path_index].back());
            gate_stack[path_index].pop_back();
        }

        while(!temp.empty())
        {
            gate_stack[path_index].push_back(temp.back());
            temp.pop_back();
        }
        return false;
    }
bool FindPathLoop(向量和门栈、整数门索引、整数路径索引)
{
向量温度;
而(!gate_stack[0][path_index].empty())
{
if(gate\u index==gate\u堆栈[0][path\u index].back())
{
而(!temp.empty())
{   
gate_堆栈[0][path_index]。向后推(temp.back());
临时弹回();
}
返回true;
}
临时推回(门栈[0][path\u index].back());
gate_堆栈[0][path_index].pop_back();
}
而(!temp.empty())
{
gate_堆栈[0][path_index]。向后推(temp.back());
临时弹回();
}
返回false;
}
布尔FindPathLoop1(堆栈和保持_边,边*p_边)
{
堆栈温度;
而(!keep_edge.empty())
{
if(p_edge==keep_edge.top())
{
而(!temp.empty())
    bool FindPathLoop(vector<vector<vector<int> > > &gate_stack, int gate_index, int path_index)
    {
        vector<int> temp;

        while(!gate_stack[0][path_index].empty())
        {
            if(gate_index == gate_stack[0][path_index].back())
            {
                while(!temp.empty())
                {   
                    gate_stack[0][path_index].push_back(temp.back());
                    temp.pop_back();
                }
                return true;
            }
            temp.push_back(gate_stack[0][path_index].back());
            gate_stack[0][path_index].pop_back();
        }

        while(!temp.empty())
        {
            gate_stack[0][path_index].push_back(temp.back());
            temp.pop_back();
        }
        return false;
    }

     bool FindPathLoop1(stack<Edge<delay_type, error_type>* > &keep_edge, Edge<delay_type, error_type> *p_edge)
     {
           stack<Edge<delay_type, error_type>* > temp;
           while(!keep_edge.empty())
           {
               if(p_edge == keep_edge.top())
               {
                   while(!temp.empty())
                   {
                       keep_edge.push(temp.top());
                       temp.pop();
                   }
                   return true;
               }
               temp.push(keep_edge.top());
               keep_edge.pop();
           }
           while(!temp.empty())
           {
               keep_edge.push(temp.top());
               temp.pop();
           }
           return false;
       }

     bool FindPathLoop2(vector<vector<int> > &gate_stack, int gate_index, int path_index)
     {
        vector<int> temp;

        while(!gate_stack[path_index].empty())
        {
            if(gate_index == gate_stack[path_index].back())
            {
                while(!temp.empty())
                {
                    gate_stack[path_index].push_back(temp.back());
                    temp.pop_back();
                }
                return true;
            }
            temp.push_back(gate_stack[path_index].back());
            gate_stack[path_index].pop_back();
        }

        while(!temp.empty())
        {
            gate_stack[path_index].push_back(temp.back());
            temp.pop_back();
        }
        return false;
    }