Guest User

Untitled

a guest
May 21st, 2019
75
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void market::updateMedian(int ID, int price) {
  2. if (lowerMedian[ID].empty()) {
  3. lowerMedian[ID].push(price);
  4. }
  5. else if (price < lowerMedian[ID].top()) {
  6. lowerMedian[ID].push(price);
  7. }
  8. else {
  9. upperMedian[ID].push(price);
  10. }
  11.  
  12. int diff = static_cast<int>(upperMedian[ID].size()) - static_cast<int>(lowerMedian[ID].size());
  13.  
  14. if ( diff < -1) {
  15. int temp = lowerMedian[ID].top();
  16. lowerMedian[ID].pop();
  17. upperMedian[ID].push(temp);
  18. }
  19. else if (diff > 1) {
  20. int temp = upperMedian[ID].top();
  21. upperMedian[ID].pop();
  22. lowerMedian[ID].push(temp);
  23. }
  24. }
RAW Paste Data