/* * Delete node function. If value to delete is found then from the certain value, * 1) if there are no children: remove self * 2) if there is one child, shift it up and remove self * 3) if there are two children, get the min from right subtree and replace it with self */ private Node m_deleteNode(ref Int32 data, ref Node self) { if (self == null) { return(self); } else if (data < self.m_getData()) { self.mLeft = this.m_deleteNode(ref data, ref self.mLeft); } else if (data > self.m_getData()) { self.mRight = this.m_deleteNode(ref data, ref self.mRight); } else { if (self.mLeft == null && self.mRight == null) { self = null; return(self); } else if (self.mLeft == null) { self = self.mRight; return(self); } else if (self.mRight == null) { self = self.mLeft; return(self); } else { Int32 tData = this.m_getMinimum(ref self.mRight).m_getData(); self.m_setData(ref tData); self.mRight = this.m_deleteNode(ref tData, ref self.mRight); } } return(self); }