public void check_duplicate_not_added() { string expected = "apri", actual; tree t = new tree(); t.add("apricot"); t.add("april"); t.add("apricots"); t.add("apricots"); bool hasValue = false; foreach (var node in t.Root.Children) { hasValue = expected == node.Value; if (hasValue) { break; } } Assert.IsTrue(hasValue); }
public void check_adds_if_new_value_is_bigger() { string expected = "apr", actual; tree t = new tree(); t.Root.Children.Add(new tree.node("ro")); t.Root.Children.Add(new tree.node("nl")); t.Root.Children.Add(new tree.node("apr")); t.Root.Children[2].Children.Add(new tree.node("rap")); t.add(expected); bool hasValue = false; foreach (var node in t.Root.Children) { hasValue = expected == node.Value; if (hasValue) { break; } } Assert.IsTrue(hasValue); }
public void check_constructs_tree_correctly_3() { string expected = "apr", actual; tree t = new tree(); t.add("apricot"); t.add("april"); t.add("apricots"); //t.add("apricots"); t.add("apricote"); t.add("apress"); bool hasValue = false; foreach (var node in t.Root.Children) { hasValue = expected == node.Value; if (hasValue) { break; } } Assert.IsTrue(hasValue); }
public void eliminacija_prefiksa() { if (this.lijevo != null) { this.lijevo.eliminacija_prefiksa(); } if (this.sredina != null) { this.sredina.eliminacija_prefiksa(); } if (this.desno != null) { this.desno.eliminacija_prefiksa(); } if (this.oznaka == '$') { tree t = new tree(); t = this.sredina.sredina; this.kopiraj_cvor(t); if (this.oznaka == '(') { t = this.sredina; this.kopiraj_cvor(t); } } }
//Tree递归调用 public List <tree> getChildren(string tableName, string fid) { DBHelperSql Dbhelper = new DBHelperSql(); List <tree> list = new List <tree>(); if (fid == "0") { tree tree1 = new tree(); tree1.id = "0"; tree1.text = "一级主栏目"; list.Add(tree1); } DataTable dt = Dbhelper.GetDataTable(tableName, " ParentId='" + fid + "' and ViewFlag='1' "); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { tree tree = new tree(); tree.id = dt.Rows[i]["id"].ToString(); tree.text = dt.Rows[i]["TitleName"].ToString(); tree.children = getChildren(tableName, dt.Rows[i]["id"].ToString()); list.Add(tree); } } else { list = null; } return(list); }
/// <summary> /// construct graphic engine for drawing states of binary tree /// </summary> /// <param name="curTree">current tree instance</param> /// <param name="margin">size of margin</param> /// <param name="radius">node's radius</param> public engine(tree curTree, int margin, int radius) { //assign fields this._tree = curTree; this._margin = margin; this._rad = radius; } //end engine constructor
//Tree递归调用 public List <tree> getChildren(string tableName, string fid, int RoleId) { DBHelperSql Dbhelper = new DBHelperSql(); List <tree> list = new List <tree>(); DataTable dt = Dbhelper.GetDataTable(tableName, " ParentId='" + fid + "' "); if (dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { tree tree = new tree(); tree.id = dt.Rows[i]["NavName"].ToString(); tree.text = dt.Rows[i]["TitleName"].ToString(); if (OperateBll.IsOkRoleoperateDataExist(dt.Rows[i]["NavName"].ToString(), RoleId)) { tree.@checked = true; } tree.children = getChildren(tableName, dt.Rows[i]["id"].ToString(), RoleId); list.Add(tree); } } else { list = null; } return(list); }
private void SetTree(tree _tree, string menuUrl, bool isIndex) { if (isIndex) { _tree.href = menuUrl; } }
public JsonResult Gettree() { List <tree> listtree = new List <tree>(); tree tree = new tree(); tree.id = "001"; tree.title = "河北省"; tree.checkArr = "0"; tree.parentId = "0"; tree tree1 = new tree(); tree1.id = "002"; tree1.title = "河南省"; tree1.checkArr = "0"; tree1.parentId = "0"; tree tree2 = new tree(); tree2.id = "003"; tree2.title = "邢台市"; tree2.checkArr = "0"; tree2.parentId = "001"; listtree.Add(tree); listtree.Add(tree1); listtree.Add(tree2); return(Json(new { data = listtree, status = new { code = "200", message = "操作成功" } }, JsonRequestBehavior.AllowGet)); }
// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Mouse0)) { if (Time.time - currentReload >= reloadTime) { Collider[] list = Physics.OverlapBox(transform.position + transform.forward * 0.5f, new Vector3(.5f, .5f, .75f), transform.rotation, mask); foreach (Collider item in list) { tree t = item.GetComponent <tree>(); if (t.wood == null) { t.wood = this.wood; } t.dealDamage(damage); } currentReload = Time.time; } } }
/// <summary> /// this function dispaly the unhashed table into console /// </summary> public void displayUnHash() { List <int> listElements = new List <int>(); // show me those hash elements for (int i = 0; i <= hash_table.Length - 1; i++) { // show me what inside of each hash element contains tree myTree = new tree(); myTree = (tree)hash_table[i]; if (myTree != null) { foreach (Nodes nodes in myTree.list_tree()) { listElements.Add(nodes.info); } } } foreach (int elements in listElements) { Console.WriteLine("-------" + elements); } }
int postorder(tree cur) { if (cur == null) { return(0); } if ((cur.left == null) && (cur.right == null)) { return(cur.val - '0'); } else { int op1 = postorder(cur.left); int op2 = postorder(cur.right); switch (cur.val) { case '+': return(op1 + op2); case '-': return(op1 - op2); case '*': return(op1 * op2); case '/': return(op1 / op2); } } return(0); }
public void uklanjanje_implikacije() { if (this.lijevo != null) { this.lijevo.uklanjanje_implikacije(); } if (this.sredina != null) { this.sredina.uklanjanje_implikacije(); } if (this.desno != null) { this.desno.uklanjanje_implikacije(); } if (this.sredina != null) { if (this.sredina.oznaka == '>') { tree t = new tree('-'); t.sredina = this.lijevo; this.lijevo = t; this.sredina.oznaka = '+'; } } }
public void check_root_node() { string expected = "$$ROOT$$", actual; tree t = new tree(); actual = t.Root.Value; Assert.AreEqual(expected, actual); }
public Node(bool _block, Vector3 _worldPosition, GridID _gridId) { block = _block; worldPosition = _worldPosition; gridId = _gridId; m_grass = default(grass); m_tree = default(tree); }
public tree() { this.tip = 0; this.oznaka = '\0'; this.lijevo = null; this.desno = null; this.sredina = null; }
public void kopiraj_cvor(tree t) { this.oznaka = t.oznaka; this.tip = t.tip; this.lijevo = t.lijevo; this.sredina = t.sredina; this.desno = t.desno; }
public void deleteTree() { if (m_tree != null) { m_tree.delete(); m_tree = default(tree); block = false; } }
void attackTree(tree treeComp) { if (treeComp.wood == null) { treeComp.wood = this.wood; } treeComp.dealDamage(damage, isChainsaw); }
// Start is called before the first frame update void Start() { tauler = new Tauler(); tauler.insertValue(); arbre = new tree(tauler, depth); //InvokeRepeating("ia", 0.01f, 0.01f); //ia(); showValues(); }
tree createtree(char c, tree left, tree right) { tree r = new tree(); r.val = c; r.left = left; r.right = right; return(r); }
/// <summary> /// construct task schedule that manages binary tree operations /// </summary> /// <param name="treeInst">tree instance on which to perform operations</param> public scheduler(PictureBox picBox, tree treeInst) { //assign picture box this._formImage = picBox; //assign tree this._tree = treeInst; //create stack this._stack = new Stack<task>(); //create drawing engine this._draw = new engine(this._tree, 50, 50); }
void preorder(tree cur) { Console.Write(cur.val + " "); if (cur.left != null) { preorder(cur.left); } if (cur.right != null) { preorder(cur.right); } }
void inorder(tree cur) { if (cur.left != null) { inorder(cur.left); } Console.Write(cur.val + " "); if (cur.right != null) { inorder(cur.right); } }
//quick function to draw the tree void drawBranch(Vector3 startingPositon,branch _branch,tree _tree,int branchChildIndex) { for (int i =0; i < _branch.contents.Length -1; i++) { Vector3 endPoint = getDriection(_branch.rotation,_branch.contents[i]); Gizmos.DrawLine(startingPositon,startingPositon + endPoint); startingPositon += endPoint; if(_branch.contents[i] == branchCharacter) { drawBranch(startingPositon,_tree.branches[branchChildIndex],_tree,branchChildIndex); branchChildIndex++; } } }
public static void Main(string[] args) { tree tree = new tree(); tree.insert(4); tree.insert(5); tree.insert(10); tree.insert(6); tree.insert(7); tree.insert(9); tree.insert(8); TraverseFunction(root); }
private void btnCreateElements_Click(object sender, EventArgs e) { tree myTree = new tree(); myTree.insert_node(4); myTree.insert_node(6); myTree.insert_node(7); myTree.insert_node(8); myTree.insert_node(1); myTree.insert_node(2); TreeNode myTreeNode = createTree(myTree.start, null, null); treeView1.Nodes.Add(myTreeNode); }
private void btnCreateTree_Click(object sender, EventArgs e) { if (listBoxElements.Items.Count > 0) { myTree = new tree(); foreach (int item in listBoxElements.Items) { myTree.insert_node(item); } populateTreeList(); } else { MessageBox.Show("First create the tree, thanks", "Result", MessageBoxButtons.OK); } }
public static void Main(string[] args) { var array = new int[5] { 3, 1, 5, 2, 4 }; tree ftree = new tree(); // for(int i =1; i < 5; i++) // { ftree.addrc(array[i]); // } // string llistelements = ""; // ftree.print(null, ref llistelements); top = ftree.ArraytoTree(array, 0, 5); ftree.preOr der(array[0]); }
void Start() { forest f = new forest (radius, density, new point(0, 0, 0)); point[] arrForest = f.CreateForest (); species aSpec = new species (); aSpec.generate (); foreach (point tree in arrForest) { Debug.Log (string.Format("Tree x: {0}, y: {1}", tree.x, tree.y)); aSpec.generate(); tree t = new tree(f_prefab); t.genTree(new Vector3(tree.x, 0, tree.y), aSpec.depth, aSpec.length, aSpec.maxHeight, Mathf.PI / 2); viewableTree v = new viewableTree(t.points); trees.Add(v); } foreach (viewableTree v in trees) { Debug.Log (string.Format("Viewable Tree start point: {0}", v.startPoint)); } }
public void populateTreeList(int hashTable) { if (treeView1.Nodes.Count > 0) { treeView1.Nodes.Clear(); } tree myTree = (tree)myHash.hash_table[hashTable]; if (myTree != null) { TreeNode myTreeNode = showTree(myTree.start, null, null); treeView1.Nodes.Add(myTreeNode); } else { MessageBox.Show("This hash table does not have elements", "Result", MessageBoxButtons.OK); } }
/// <summary> /// 根据一级菜单加载子菜单列表 /// </summary> /// <returns></returns> private void GetMenusByRootMenuId(List <tree> treeList, IEnumerable <MenuModel> allMenus, tree tree, int menuId, bool isIndex) { var childMenus = allMenus.Where(x => x.ParentId == menuId).OrderBy(x => x.OrderNo); if (childMenus != null && childMenus.Count() > 0) { List <tree> _children = new List <tree>(); foreach (var m in childMenus) { var _tree = new tree { id = m.Id, name = m.MenuName, title = m.MenuName, icon = m.MenuIcon }; SetTree(_tree, m.MenuUrl, isIndex); _children.Add(_tree); tree.children = _children; GetMenusByRootMenuId(treeList, allMenus, _tree, m.Id, isIndex); } } }
private void RenderTerrain(float[,] h, float[,] w, Vector3 player) { for (int i = (int)(player.x - renderDistance/2); i < (int)(player.x + renderDistance/2); i++) for (int j = (int)(player.z - renderDistance / 2); j < (int)(player.z + renderDistance / 2); j++) { try { for (int k = 0; k < h[i, j] * MaxHeight + 1; k++) { if (k >= (int)(h[i, j] * MaxHeight) - 2) { if (w[i, j] < waterLevel && !Physics.CheckSphere(new Vector3(i, k, j), .25f)) Instantiate(Land, new Vector3(i, k, j), Quaternion.identity); else if (!Physics.CheckSphere(new Vector3(i, k, j), (float)(0.25))) Instantiate(Water, new Vector3(i, k, j), Quaternion.identity); } if (texture.GetPixel(i, j).r >= .1f && !Physics.CheckSphere(new Vector3(i, h[i, j] * MaxHeight + 2, j), .25f) && w[i,j] < waterLevel) { if (!treeMap.ContainsKey(new point(i, j,(int) (h[i, j] * MaxHeight + 1)))) { tree Tree = new tree(TreeTrunk); Tree.genTree(new Vector3(i, h[i, j] * MaxHeight + 1, j), 5, 5, 10, Mathf.PI / 2); treeMap.Add(new point(i, j, (int)(h[i, j] * MaxHeight + 1)), Tree); } tree Tree1; treeMap.TryGetValue(new point(i, j,(int) (h[i, j] * MaxHeight + 1)), out Tree1); Tree1.generate(); } } } catch { } } }
//creates the base tree tells the connect connectBranches to make branches accordingly void generateTree() { branch trunk = new branch (treeRules.runRules (treeHeight, 'u')); myTree = new tree (trunk, connectBranches(trunk)); }