Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Graph 查找图形中的所有边类型。树、向前、向后或交叉边_Graph_Pseudocode_Edges - Fatal编程技术网

Graph 查找图形中的所有边类型。树、向前、向后或交叉边

Graph 查找图形中的所有边类型。树、向前、向后或交叉边,graph,pseudocode,edges,Graph,Pseudocode,Edges,我花了几个小时寻找一个伪代码来计算图形中的边类型。我找不到完整的版本,所以我写了一个新的。我将把它作为对这篇文章的回复分享,以便其他人可以在需要时访问它。edgeTypes(G,Source) edgeTypes(G, Source) time = 1 Stack s for each(node in G.vertices) node.start = 0 node.finish = 0 s.push(Source) wh

我花了几个小时寻找一个伪代码来计算图形中的边类型。我找不到完整的版本,所以我写了一个新的。我将把它作为对这篇文章的回复分享,以便其他人可以在需要时访问它。

edgeTypes(G,Source)
edgeTypes(G, Source)
    time = 1
    Stack s
    for each(node in G.vertices)
        node.start = 0
        node.finish = 0

    s.push(Source)

    while(!s.isEmpty())
        node = s.peek()
        if(node.start > 0)
            node.finish = time++
            s.pop()
        else
            node.start = time++
            for each(neig in node.neighbors)
                if(neig.start == 0)
                    |node, neig|.type = 'tree'
                else if(neig.finish == 0)
                    |node, neig|.type = 'back'
                else if(node.start < neig.start)
                    |node, neig|.type = 'forward'
                else |node, neig|.type = 'cross'

                if(neig.start == 0)
                    s.push(neig)
时间=1 堆叠 对于每个(G顶点中的节点) node.start=0 node.finish=0 s、 推送(源) 而(!s.isEmpty()) node=s.peek() 如果(node.start>0) node.finish=时间++ s、 流行音乐() 其他的 node.start=时间++ 对于每个节点(节点邻居中的neig) 如果(neig.start==0) |节点,neig |。类型='tree' else if(neig.finish==0) |节点,neig |。类型='back' else if(node.start
您应该将问题重新表述为实际问题。你应该在回答中解释代码。这不是一个论坛。您希望添加到SO的Q&A数据库,这很好,但请确保您确实发布了问题和答案,而不是轶事和代码转储。谢谢