```
private List<double> m_listNum = new List<double>();
public void AddNum(double num) {
int lintPos = m_listNum.BinarySearch( num ) ;
if (lintPos >= 0) {
m_listNum.Insert(lintPos, num);
} else {
lintPos = ~lintPos;
if (lintPos == m_listNum.Count) {
m_listNum.Add(num);
} else {
m_listNum.Insert(lintPos, num);
}
}
}
// return the median of current data stream
public double FindMedian() {
int lintCount = m_listNum.Count ;
if (lintCount == 0 ) throw new Exception("array is empty");
if (lintCount % 2 == 0)
return (m_listNum[lintCount / 2 - 1] + m_listNum[lintCount / 2]) / 2;
else
return m_listNum[lintCount / 2];
}
```