标签:list style node code int out oid ack bsp
//深度遍历 private void depthQuery(Node root){ Stack<Node> stack = new Stack<Node>(); stack.push(root); while (stack.empty() ==false){ Node node = stack.pop(); System.out.println(node.value); if (root.right !=null){ stack.push(root.right); } if (root.left !=null){ stack.push(root.left); } } } //广度遍历 private void wideQuery(Node root){ Queue<Node> queue = new LinkedList<Node>(); queue.offer(root); while (queue.size() !=0){ Node node = queue.poll(); System.out.println(node.value); if (node.left !=null){ queue.offer(node.left); } if (node.right !=null){ queue.offer(node.right); } } }
标签:list style node code int out oid ack bsp
原文地址:https://www.cnblogs.com/52hadoop/p/9768036.html