File tree 1 file changed +9
-7
lines changed
1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -91,20 +91,22 @@ struct BinaryHeap {
91
91
}
92
92
93
93
void remove (size_t key) {
94
- std::swap (
95
- this ->container ->begin ()[key],
96
- this ->container ->begin ()[this ->container ->size () - 1 ]
97
- );
98
- this ->container ->pop_back ();
99
- this ->sift_down (key);
94
+ if (this ->container ->size () > key) {
95
+ std::swap (
96
+ this ->container ->begin ()[key],
97
+ this ->container ->begin ()[this ->container ->size () - 1 ]
98
+ );
99
+ this ->container ->pop_back ();
100
+ this ->sift_down (key);
101
+ }
100
102
}
101
103
102
104
void pop () {
103
105
this ->del (0 );
104
106
}
105
107
106
108
void change (size_t key, T new_value) {
107
- if (this ->container ->begin ()[key] != new_value) {
109
+ if (this ->container ->size () > key && this -> container -> begin ()[key] != new_value) {
108
110
this ->container ->begin ()[key] = new_value;
109
111
if (
110
112
key > 0 &&
You can’t perform that action at this time.
0 commit comments