private NodeBTLinked FindElement(int value, out NodeBTLinked parent) { var current = _head.Value; parent = null; while (current != null) { if (current.Value > value) { parent = current; current = current.Left; } else if (current.Value < value) { parent = current; current = current.Right; } else { break; } } return(current); }
private void AddTo(NodeBTLinked node, int value) { if (node.Value > value) { if (node.Left == null) { node.Left = new NodeBTLinked(value); } else { AddTo(node.Left, value); } } else if (node.Value < value) { if (node.Right == null) { node.Right = new NodeBTLinked(value); } else { AddTo(node.Right, value); } } }
private int Width(NodeBTLinked node) { var maxWidth = 0; var height = Height(node); for (var i = 1; i <= height; i++) { var width = GetWidth(node, i); if (width > maxWidth) { maxWidth = width; } } return(maxWidth); }
private int GetWidth(NodeBTLinked node, int level) { if (node == null) { return(0); } if (level == 1) { return(1); } else if (level > 1) { return(GetWidth(node.Left, level - 1) + GetWidth(node.Right, level - 1)); } var count = GetWidth(node.Right, level - 1); return(count); }
private int Height(NodeBTLinked node) { var count = 0; var leftHeight = 0; var rightHeight = 0; if (node == null) { return(0); } if (node.Left != null) { leftHeight = Height(node.Left); } if (node.Right != null) { rightHeight = Height(node.Right.Right); } count = Math.Max(leftHeight, rightHeight) + 1; return(count); }
private int Width(NodeBTLinked node) { var maxWidth = 0; var height = Height(node); for (var i = 1; i <= height; i++) { var width = GetWidth(node, i); if (width > maxWidth) { maxWidth = width; } } return maxWidth; }
private int Height(NodeBTLinked node) { var count = 0; var leftHeight = 0; var rightHeight = 0; if (node == null) { return 0; } if (node.Left != null) { leftHeight = Height(node.Left); } if (node.Right != null) { rightHeight = Height(node.Right.Right); } count = Math.Max(leftHeight, rightHeight) + 1; return count; }
private int GetWidth(NodeBTLinked node, int level) { if (node == null) { return 0; } if (level == 1) { return 1; } else if (level > 1) { return GetWidth(node.Left, level - 1) + GetWidth(node.Right, level - 1); } var count = GetWidth(node.Right, level - 1); return count; }
private NodeBTLinked FindElement(int value, out NodeBTLinked parent) { var current = _head.Value; parent = null; while (current != null) { if (current.Value > value) { parent = current; current = current.Left; } else if (current.Value < value) { parent = current; current = current.Right; } else { break; } } return current; }