Advertisement
Guest User

Untitled

a guest
Nov 19th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. T pop()
  2. {
  3. if (this->counter == 0)
  4. {
  5. const T to_ret = this->array[0];
  6. this->reset_();
  7. return to_ret;
  8. }
  9. else
  10. {
  11. const T to_ret = this->array[0];
  12.  
  13. this->array[0] = this->array[--this->counter];
  14. this->array[this->counter] = 0;
  15. unsigned int current = 0;
  16. unsigned left = current * 2 + 1;
  17. unsigned right = current * 2 + 2;
  18.  
  19. while ((this->array[current] <= this->array[left]) || (this->array[current] < this->array[right]))
  20. {
  21. left = current * 2 + 1;
  22. right = current * 2 + 2;
  23. if (right >= this->counter || left >= this->counter)
  24. break;
  25.  
  26. if ((this->array[left] - this->array[current]) > (this->array[right] - this->array[current]))
  27. {
  28. T tmp = this->array[current];
  29. this->array[current] = this->array[left];
  30. this->array[left] = tmp;
  31. current = left;
  32. }
  33. else
  34. {
  35. T tmp = this->array[current];
  36. this->array[current] = this->array[right];
  37. this->array[right] = tmp;
  38. current = right;
  39. }
  40. }
  41. return to_ret;
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement