private void AddNode() { int newId = TreeScript.GetNewId(); TNode child = node.AddChild(newId); GameObject obj = Instantiate(nodePrefab, transform); TreeScript.AddNode(obj); childs.Add(obj); obj.transform.Translate(new Vector3(0, -100, 0), Space.Self); obj.GetComponent <NodeScript>().SetData(child, tree, gameObject, nodePrefab); ResizeChilds(); }
private void dodajWęzełToolStripMenuItem_Click(object sender, EventArgs e) { NodeTextDialog dlg = new NodeTextDialog(); if (dlg.ShowDialog() == DialogResult.OK) { if (String.IsNullOrEmpty(dlg.txtNodeText.Text)) { return; } SelectedNode.AddChild(int.Parse(dlg.txtNodeText.Text)); // Rearrange the tree to show the new node. ArrangeTree(); } }
private void recursiveDfs(TNode node) { if (node.Color == NodeColor.Gray) { throw new Exception("NIE"); } node.start = time++; node.Color = NodeColor.Gray; foreach (var item in graf[node]) { //item.Parent = node; node.AddChild(item); recursiveDfs(item); } node.Color = NodeColor.Black; node.finish = time++; stack.Push(node); }
public TNode decode(List <int> sequence) { List <int> b = new List <int>(); for (int x = 1; x <= sequence.Count + 2; x++) { b.Add(x); } List <int> copySequence = sequence.ToList(); List <TNode> allNodes = new List <TNode>(); TNode root = new TNode(sequence.First()); allNodes.Add(root); while (sequence.Count != 0) { int minNodeInb = b.Where(y => !sequence.Any(y2 => y2 == y)).Min(); int firstInSequence = sequence.First(); TNode nodeToLink = FindNodeInList(allNodes, firstInSequence); TNode x2 = FindNodeInList(allNodes, minNodeInb); if (nodeToLink == null) { nodeToLink = new TNode(firstInSequence); if (x2 == null) { nodeToLink.AddChild(minNodeInb); allNodes.Add(nodeToLink); } else { nodeToLink.AddChild(x2); } } else { if (x2 == null) { nodeToLink.AddChild(minNodeInb); } else { nodeToLink.AddChild(x2); } } sequence.Remove(sequence.First()); b.Remove(minNodeInb); } TNode lastChild = FindNodeInList(allNodes, b.First()); TNode lastlink = FindNodeInList(allNodes, b[1]); if (lastChild == null) { lastChild = new TNode(b.First()); } if (lastlink == null) { lastlink = new TNode(b[1]); } lastlink.AddChild(lastChild); // if (lastChild != null) // { // lastChild.AddChild(lastlink); // } // else // { // root.FindChild(b[1]).AddChild(b.First()); //} return(recursiveFindRoot(root));//FindRootInList(allNodes); }
public TNode decode5(List <int> a) { List <int> b = new List <int>(); for (int x = 1; x <= a.Count + 2; x++) { b.Add(x); } TNode root = new TNode(1); HashSet <TNode> reminidingNodes = new HashSet <TNode>(); while (b.Count != 2) { int minb = b.Where(y => !a.Any(y2 => y2 == y)).Min(); int firstA = a.First(); TNode parent = null; TNode child = null; TNode node = root.FindChild(firstA); //sprawdzenie w root A if (node == null) { node = root.FindChild(minb); } //sprawdzenie w root B if (node == null) { node = FindNodeInList(reminidingNodes, minb); } //sprawdzenie czy istnieje w liscie min b if (node == null) { node = FindNodeInList(reminidingNodes, firstA); } //sprawdzenie czy istnieje w liście firstA if (node != null) { parent = node; } //jeśli nie istnieje rodzic stwórz go if (parent == null) { if (firstA < minb) { parent = new TNode(firstA); } else { parent = new TNode(minb); } } //jeśli nie istnieje dziecko stwórz go int childLabel = 0; if (parent.label == firstA) { childLabel = minb; } else { childLabel = firstA; } child = root.FindChild(childLabel); if (child == null) { child = FindNodeInList(reminidingNodes, childLabel); } if (child == null) { child = new TNode(childLabel); } parent.AddChild(child); if (parent != root) { reminidingNodes.Add(parent); } a.Remove(a.First()); b.Remove(minb); } TNode childLast = null; TNode parentLast = root.FindChild(b[0]); if (parentLast == null) { parentLast = root.FindChild(b[1]); } childLast = root.FindChild(parentLast.label == b[0] ? b[1] : b[0]); if (childLast == null) { childLast = FindNodeInList(reminidingNodes, parentLast.label == b[0] ? b[1] : b[0]); } if (childLast == null) { childLast = new TNode(parentLast.label == b[0] ? b[1] : b[0]); } parentLast.AddChild(childLast); return(root); }