tree

inserting in binary tree doesn't work using java

流过昼夜 提交于 2021-02-17 03:03:50
问题 I'm currently learning about trees using java and i have some errors going on here in the insertion of items in a binary tree I don't why it doesn't work this is the code: tree node: public class TNode { int data; TNode left; TNode right; public TNode(int data) { this.data = data; left = null; right = null; } } tree class: public class Tree { TNode root; public Tree(){ root = null; } public TNode insertNode(TNode item, int d) { if (item == null) { return new TNode(d); } if (d < item.data) {

php function returns null instead of string

こ雲淡風輕ζ 提交于 2021-02-16 15:09:47
问题 I have an array with all categories stored in it: $allCatArray = array( ['departments/outdoor/123123/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/123123/' [pid] => 'departments/outdoor/' [name] => 'Child Category Name' ) ['departments/outdoor/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/' [pid] => '0' [name] => 'Main Category Name' ) I need detect the highest category in hierarchy when i have id of lower category in hierarchy. So I have this function:

php function returns null instead of string

烈酒焚心 提交于 2021-02-16 15:09:37
问题 I have an array with all categories stored in it: $allCatArray = array( ['departments/outdoor/123123/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/123123/' [pid] => 'departments/outdoor/' [name] => 'Child Category Name' ) ['departments/outdoor/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/' [pid] => '0' [name] => 'Main Category Name' ) I need detect the highest category in hierarchy when i have id of lower category in hierarchy. So I have this function:

php function returns null instead of string

十年热恋 提交于 2021-02-16 15:09:29
问题 I have an array with all categories stored in it: $allCatArray = array( ['departments/outdoor/123123/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/123123/' [pid] => 'departments/outdoor/' [name] => 'Child Category Name' ) ['departments/outdoor/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/' [pid] => '0' [name] => 'Main Category Name' ) I need detect the highest category in hierarchy when i have id of lower category in hierarchy. So I have this function:

php function returns null instead of string

若如初见. 提交于 2021-02-16 15:09:19
问题 I have an array with all categories stored in it: $allCatArray = array( ['departments/outdoor/123123/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/123123/' [pid] => 'departments/outdoor/' [name] => 'Child Category Name' ) ['departments/outdoor/'] => stdClass Object ( [i] => 1 [id] => 'departments/outdoor/' [pid] => '0' [name] => 'Main Category Name' ) I need detect the highest category in hierarchy when i have id of lower category in hierarchy. So I have this function:

【LeetCode OJ】Maximum Depth of Binary Tree

杀马特。学长 韩版系。学妹 提交于 2021-02-12 05:49:44
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf node. /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { private int max = 0; public void preOrder(TreeNode root, int depth){ if(root == null)return; preOrder(root.left, depth + 1); if(max < depth) max = depth; preOrder(root.right, depth + 1); } public int maxDepth(TreeNode root) { preOrder(root, 1); return max; } } 来源: oschina

【LeetCode OJ】Same Tree

ε祈祈猫儿з 提交于 2021-02-12 05:43:33
Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurally identical and the nodes have the same value. /** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */ public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { return preOrder(p, q); } public boolean preOrder(TreeNode p, TreeNode q) { if (p == null && q == null) return true; if((p == null && q != null) || (q == null && p != null)) return false; if(

Building a tree using nested unordered lists

时光怂恿深爱的人放手 提交于 2021-02-11 15:49:59
问题 How can I build this HTML code: <ul class="tree"> <li>Animals <ul> <li>Birds</li> <li>Mammals <ul> <li>Elephant</li> <li>Mouse</li> </ul> </li> <li>Reptiles</li> </ul> </li> <li>Plants <ul> <li>Flowers <ul> <li>Rose</li> <li>Tulip</li> </ul> </li> <li>Trees</li> </ul> </li> </ul> From this structure: CREATE TABLE `categories` ( `id` INT(11) NOT NULL AUTO_INCREMENT, `position` INT(11) DEFAULT NULL, `parent_id` INT(11) DEFAULT NULL, PRIMARY KEY (`id`), KEY `parent_id_fk` (`parent_id`),

Linux: device tree to acpi driver

孤者浪人 提交于 2021-02-11 15:28:56
问题 I need help on this, my driver already work on device tree mode, and I want support acpi mode for it, I'm stuck on create partitions: Device Tree: &spi0 { status = "ok"; flash: n25q256a@0 { status = "ok"; cell-index = <0>; #address-cells = <1>; #size-cells = <1>; compatible = "n25q256a"; reg = <0>; spi-max-frequency = <15000000>; spi-cpha; spi-cpol; partition@0x00000000 { label = "Boot loader"; reg = <0x00000000 0x01000000>; }; partition@0x01000000 { label = "n25q256a-test"; reg = <0x01000000

Why is my program leaking memory? (working with trees in C++)

允我心安 提交于 2021-02-11 13:47:46
问题 I'm creating a tree of dynamic objects. The Node class has a vector to store the child nodes, among the other class variables: std::vector<Node*> child; The class destructor deletes all the dynamically allocated class variables, and then deletes the child nodes: ~Node() { //Deleting the other variables . . . //Deleting the child nodes for(int i = 0; i < child.size(); i++) { delete child[i]; } } My class has a method that creates a tree of a given height, in which the current node is the root