赞
踩
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; } } } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。