Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- T pop()
- {
- if (this->counter == 0)
- {
- const T to_ret = this->array[0];
- this->reset_();
- return to_ret;
- }
- else
- {
- const T to_ret = this->array[0];
- this->array[0] = this->array[--this->counter];
- this->array[this->counter] = 0;
- unsigned int current = 0;
- unsigned left = current * 2 + 1;
- unsigned right = current * 2 + 2;
- while ((this->array[current] <= this->array[left]) || (this->array[current] < this->array[right]))
- {
- left = current * 2 + 1;
- right = current * 2 + 2;
- if (right >= this->counter || left >= this->counter)
- break;
- if ((this->array[left] - this->array[current]) > (this->array[right] - this->array[current]))
- {
- T tmp = this->array[current];
- this->array[current] = this->array[left];
- this->array[left] = tmp;
- current = left;
- }
- else
- {
- T tmp = this->array[current];
- this->array[current] = this->array[right];
- this->array[right] = tmp;
- current = right;
- }
- }
- return to_ret;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement