public void Add(MedianTreeNode newNode) { this.Count++; if (this.rootNode == null) { this.rootNode = newNode; return; } MedianTreeNode nextNode = this.rootNode; while (nextNode != null) { if (nextNode.Value.CompareTo(newNode.Value) > 0) { nextNode.LeftTreeCount++; if (nextNode.LeftNode != null) { nextNode = nextNode.LeftNode; } else { nextNode.LeftNode = newNode; newNode.ParentNode = nextNode; nextNode = null; } } else { nextNode.RightTreeCount++; if (nextNode.RightNode != null) { nextNode = nextNode.RightNode; } else { nextNode.RightNode = newNode; newNode.ParentNode = nextNode; nextNode = null; } } } }
public int GetMedianModulo(string fileName) { this.TotalMedian = 0; this.tree = new MedianTree(); string[] stream = File.ReadAllLines(@fileName); foreach (string newValue in stream) { int newIntValue = Convert.ToInt32(newValue); MedianTreeNode newNode = new MedianTreeNode(newIntValue); this.tree.Add(newNode); int currentMedian = this.tree.GetCurrentMedian(); this.TotalMedian = TotalMedian + currentMedian; } return this.TotalMedian%this.tree.Count; }