public void add(int value) { if (top == null) { Node newNode = new Node(value); top = newNode; return; } Node currNode = top; bool added = false; do { if (value < currNode.Value) { if (currNode.Left == null) { Node newNode = new Node(value); currNode.Left = newNode; added = true; } else { currNode = currNode.Left; } } if (value >= currNode.Value) { if (currNode.Right == null) { Node newNode = new Node(value); currNode.Right = newNode; added = true; } else { currNode = currNode.Right; } } } while (!added); }
public Tree(int initial) { top = new Node(initial); }
public Tree() { top = null; }
public Node(int initial) { Value = initial; Left = null; Right = null; }
private void addR(ref Node n, int value) { if (n == null) { Node newNode = new Node(value); n = newNode; return; } if (value < n.Value) { addR(ref n.Left, value); return; } if (value >= n.Value) { addR(ref n.Right, value); return; } }
public void Print_PreOrder(Node N, ref string s) { if (N == null) { N = top; s = s + N.Value.ToString().PadLeft(3); } if (N.Left != null) { Print_InOrder(N.Left, ref s); s = s + N.Value.ToString().PadLeft(3); } if (N.Right != null) { Print_InOrder(N.Right, ref s); } }