美文网首页
拓扑排序

拓扑排序

作者: 小幸运Q | 来源:发表于2018-07-07 14:28 被阅读2次

    鸣谢:https://blog.csdn.net/qq_35644234/article/details/60578189

    image.png

    过程:

    1. 初始化
      发现degree[6]==0且degree[1]==0,删除它边上的边,将该节点加入queue中。


      image.png
    2. pop该点,将它的下游节点的degree--,如果degree--后为0也放入队列里面。


      image.png
    3. 当queue不为空,继续...


      image.png

    如果需要对编号有要求,必须是

    相关文章

      网友评论

          本文标题:拓扑排序

          本文链接:https://www.haomeiwen.com/subject/zcnbuftx.html