当前位置:   article > 正文

图的深度优先遍历_本关任务:请你实现 graph.cpp 里的int graph_widthfirst(graph*g

本关任务:请你实现 graph.cpp 里的int graph_widthfirst(graph*g, int start, edg
public void f(Node ndoe){
	if(node == null){
		return; 
	}
	Stack<Node> stack = new Stack<>();
	HashSet<Node> HashSet = new HashSet<>();
	stack.add(node);
	HashSet.add(node);
	System.out.println(node.value);
	while(!stack.isEmpty()){
		Node cur = queue.poll();
		for(Node next: cur.nexts){
			if(!HashSet.contains(cur)){
				 stack.push(cur);
				 stack.push(next);
				 HashSet.add(next);
				 System.out.println(next.value);
				 break;
			 }
		} 
	}
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/509698
推荐阅读
  

闽ICP备14008679号