public Node GetRight() { if(right==null) right = new Node(); return this.right; }
public Node(int i, int v) { _index = i; value = v; left = null; right= null; }
public Node GetLeft() { if (left == null) left = new Node(); return this.left; }
//zbiera liscie w kolejności od lewej poziomu "l" drzewa public void Collect(Node el, int l, ref StringBuilder ss) { if (el != null) { Collect(el.left, l, ref ss); Collect(el.right, l, ref ss); if (el.level == l) { //for (int i = 0; i < treeDepth/(l+1); i++) //{ // ss.Append(" "); //} ss.Append(el.index.ToString()); //for (int i = 0; i < treeDepth; i++) //{ // ss.Append(" "); //} } //else //{ // for (int i = 0; i <this.treeDepth* (l + 3) / (l + 5); i++) // //for (int i = 0; i < this.treeDepth / (l + 2); i++) // ss.Append(" "); //} } else ss.Append(" "); }
public Node Get(Node elem, int i) { if (elem != null) { if (elem.index < i) elem = Get(elem.right, i); else if (elem.index > i) elem = Get(elem.left, i); } return elem; }
public Node Insert(Node elem, int i, int val, int dep) { if (elem == null) { elem = new Node(i, val); elem.level = dep; } else if (elem.index < i) elem.right = Insert(elem.right, i, val, ++dep); else if (elem.index > i) elem.left = Insert(elem.left, i, val, ++dep); else { elem.value = val; return elem; } if (dep > this.treeDepth) treeDepth = dep; return elem; }
// Left Visit Right, drukowanie infiksowe(in-order) public void Print(Node el) { if (el != null) { Print(el.left); Console.WriteLine(el.value+"\t"+el.index); Print(el.right); } }
public Tree() { //root = new Node(0, v); root = null; treeDepth = 0; }