/// <summary> /// Searches for an parent of element that matches the conditions defined by the specified /// </summary> /// <param name="node"></param> /// <returns></returns> public Tuple <Node <T>, int> FindParent(Node <T> node) { int check = 0; if (node == null) { return(null); } Node <T> temp = root; Node <T> parent = null; while (temp != null) { if (temp.CompareTo(node) == 0) { return(new Tuple <Node <T>, int>(parent, check));// temp; } if (temp > node) { parent = temp; check = -1; temp = temp.Left; } else { parent = temp; check = 1; temp = temp.Right; } } return(null); }
/// <summary> /// Determines whether an element is in the AVL /// </summary> /// <param name="node"></param> /// <returns></returns> public bool Contains(Node <T> node) { Node <T> temp = root; if (node == null) { return(false); } while (temp != null) { if (temp.CompareTo(node) == 0) { return(true); } if (temp > node) { temp = temp.Left; } else { temp = temp.Right; } } return(false); }
/// <summary> /// Searches for the element that matches the conditions defined by the specified /// </summary> /// <param name="node"></param> /// <param name="data"></param> /// <returns></returns> public Node <T> FindNode(Node <T> node) { Node <T> temp = root; if (node == null) { return(null); } while (temp != null) { if (temp.CompareTo(node) == 0) { return(temp); } if (temp > node) { temp = temp.Left; } else { temp = temp.Right; } } return(null); }
private Node <T> Find(T value) { Node <T> current = Head; while (current != null) { int result = current.CompareTo(value); if (result > 0) { current = current.Left; } else if (result < 0) { current = current.Right; } else { break; } } return(current); }