图宽度优先遍历

public DFS(Node node)
{
    Queue<Node> queue=new Queue<>();
    HashSet set=new HashSet<>();

    queue.add(node);
    set.add(node);
    while(!queue.isEmpty())
    {
        Node q=queue.poll();
//直接输出
    //    Iterater iterater=set.iterater();
     //   while(iterater.hasnext())

        //这里不是对队列遍历,而是对数据机构结点中的下一个结点链表遍历
        for (Node next : q.nodes) {
        if(!set.contains(next))
        {
            set.add(next);
            queue.add(next);
        }
}
    }

}
全部评论

相关推荐

点赞 评论 收藏
分享
nus2201602...:兄弟,你这个简历撕了丢了吧,就是一坨,去找几个项目,理解项目流程,看几遍就是你的了,看看八股就去干了,多看看牛客里别人发出来的简历,对着写,你这写的啥啊,纯一坨
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-10 11:33
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务