Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void market::updateMedian(int ID, int price) {
- if (lowerMedian[ID].empty()) {
- lowerMedian[ID].push(price);
- }
- else if (price < lowerMedian[ID].top()) {
- lowerMedian[ID].push(price);
- }
- else {
- upperMedian[ID].push(price);
- }
- int diff = static_cast<int>(upperMedian[ID].size()) - static_cast<int>(lowerMedian[ID].size());
- if ( diff < -1) {
- int temp = lowerMedian[ID].top();
- lowerMedian[ID].pop();
- upperMedian[ID].push(temp);
- }
- else if (diff > 1) {
- int temp = upperMedian[ID].top();
- upperMedian[ID].pop();
- lowerMedian[ID].push(temp);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement