public void Insert(NodeTree node) { if (Root == null) { Root = node; return; } NodeTree curNode = Root; while (true) { if(node.Data > curNode.Data && curNode.Right == null) { curNode.Right = node; return; } else if (node.Data > curNode.Data && curNode.Right != null) { curNode = curNode.Right; } else if (node.Data < curNode.Data && curNode.Left == null) { curNode.Left = node; return; } else if (node.Data < curNode.Data && curNode.Left != null) { curNode = curNode.Left; } } }
public static void PreOrder(NodeTree node) { if (node == null) return; Console.WriteLine(node.Data); PreOrder(node.Left); PreOrder(node.Right); }
public void InOrder(NodeTree node) { if (node == null) return; InOrder(node.Left); Console.WriteLine(node.Data); InOrder(node.Right); }