///<summary>Преобразовать в строку, со скобками. ///Скобки указывают вложенность узлов. Сама строка окружена фигурными скобками.</summary> public override String ToString() { StringBuilder sb = new StringBuilder(); HashSet <Node <T> > hs = new HashSet <Node <T> >(); CSharpDataStructures.Structures.Lists.LinkedStack <Node <T> > STACK = new CSharpDataStructures.Structures.Lists.LinkedStack <Node <T> >(); Node <T> n; STACK.Push(Root());//_cellspace[0] while (!STACK.IsEmpty()) { n = STACK.Top(); if (hs.Contains(n)) { STACK.Pop(); sb.Append("}"); } else { hs.Add(n); sb.Append("{" + n.Value.ToString()); IList <Node <T> > children = GetChildren(n); for (Int32 c = children.Count - 1; c >= 0; c--) { STACK.Push(children[c]); } } } return(sb.ToString()); }
//Compute new count for new sub_tree. private void __ComputeC(ref Int32 nc) { HashSet <Node <T> > hs = new HashSet <Node <T> >(); CSharpDataStructures.Structures.Lists.LinkedStack <Node <T> > STACK = new CSharpDataStructures.Structures.Lists.LinkedStack <Node <T> >(); Node <T> n; STACK.Push(Root()); while (!STACK.IsEmpty()) { n = STACK.Top(); if (hs.Contains(n)) { STACK.Pop(); } else { hs.Add(n); nc++; IList <Node <T> > children = GetChildren(n); for (Int32 c = children.Count - 1; c >= 0; c--) { STACK.Push(children[c]); } } } }