protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { //add dummy nodes TreeView1.Nodes.Add(new TreeNode() { Value = "1", Text = "One" }); TreeView1.Nodes.Add(new TreeNode() { Value = "2", Text = "Two" }); TreeView1.Nodes.Add(new TreeNode() { Value = "3", Text = "Three" }); //call recursive function to remove hyperlinks RemoveHyperLinks(TreeView1, TreeView1.Nodes); } }
public void bbst(int array[]) { root = new TreeNode(); balancedBST(array, 0, array.length - 1, root); }
} else if (preorder[i] == '0') { TreeNode subTree = new TreeNode(); subTree.value = '0'; tree.rigth = subTree; i++;
else if(key.compareTo(subroot.key) < 0){ if(subroot.left != null){ subroot = root.left; // WHERE ARE YOU USING KEY OF THIS NEW NODE subroot FOR COMPARISON? return insertWord(key, meaning); } else{ subroot.left = new TreeNode(); subroot.left.key = key; subroot.left.meaning = meaning; } }
TreeNode child = new TreeNode("Tab"); Singleton.getInstance().getTopRootNode().addChild(child);
while (stack of pairs processing is not finished) { //get next pair and process the pair sub(next pair); } public TreeNode sub(int[] num, int start, int end) { int indexRoot = (start+end+1) / 2; TreeNode root = new TreeNode(num[indexRoot]); if(indexRoot > start) { root.left = addToStack(num, 0, indexRoot-1); } if(indexRoot < end) { root.right = addToStack(num, indexRoot+1, end); } return root; }
public void myInsert(char ch, Stack<TreeNode> s) { if (Character.isDigit(ch)) { // leaf (literal) s.push(new TreeNode(ch)); } else { // operator node TreeNode tParent = new TreeNode(ch); // add operands tParent.right = s.pop(); tParent.left = s.pop(); // push result to operand stack s.push(tParent); } }
ArrayList<Integer> data = new ArrayList<Integer>; while(InputFile.hasNext()){ data.add(InputFile.nextInt()); } //end while TreeNode T = new TreeNode(); for(i=0; i<data.length(); i++){ T = insert(T, data[i]); } //end for return T;
private static void createTree(String homeStation) { root = new TreeNode(homeStation); List<String> addedList = new ArrayList<String>(); addedList.add(homeStation); addNodesRecursive(root, addedList); }
var node_a = new TreeNode(); var node_b = new TreeNode(node_a); var node_c = new TreeNode(node_a); console.log(node_a.getParent(), node_c.get_parent()); //null , node_a console.log(node_a.getChildren()); //[node_b, node_c]
private TreeNode handleNode(TreeNode node, int val) { if(node == null) node = new TreeNode(val, this); else node.insert(val); return node; }
public static void main(String[] args) { Scanner input = new Scanner(System.in); int x = input.nextInt(); TreeNode root = new TreeNode(x); while(true) { String str = input.next(); if(str.equals("-")) insert(root); else insert(root, Integer.parseInt(str)); } }
private TreeNode insert(TreeNode temp,int x){ if(temp == null){ temp = new TreeNode(); temp.key = x; temp.left = temp.right = null; } if(temp.key > x) temp.left = insert(temp.left,x); else if(temp.key < x) temp.right = insert(temp.right,x); return temp; }
public TreeNode deSerialize(TreeNode root, String s) { String[] split = s.split("\\s+"); root = deSerialize( split, new int[1]{0}); return root; } public TreeNode deSerialize( String[] s, int[] i) { if(i[0] >= s.length || s[i[0]].equals("null")) return null; else { int v = (int) s[i[0]].charAt(0) - '0'; TreeNode root = new TreeNode(v); root.left = deSerialize( s, ++i[0]); root.right = deSerialize( s, ++i[0]); return root; } }
TreeNode createTree(int[] a, Index i, int min, int max) { if (i.index >= a.length) { return null; } if (a[i.index] > min && a[i.index] < max) { int current = a[i.index]; TreeNode t = new TreeNode(a[i.index]); i.index = i.index + 1; t.left = createTree(a, i, min, current); t.right = createTree(a, i, current, max); return t; } return null; }
TreeNode rootNode = new TreeNode(); rootNode.setCanAcceptDrop(false); rootNode.setID("0"); rootNode.setAttribute("Name","ROOT"); rootNode.setIcon("16/root.png"); tree.setRoot(rootNode);
private TreeNode insertNode(TreeNode node, int key){ if (node == null){ node = new TreeNode(key); } else{ if (node.getKey() > key){ node.setChildLeft(insertNode(node.getChildLeft(), key)); } else if (node.getKey() < key){ node.setChildRight(insertNode(node.getChildRight(), key)); } else{ // dont do anything } } return node; }