I apologize if this is a duplicate. I promise I tried to find an answer first.
I want to make a binary heap using a vector. To do so, I have to implement a pop function, that removes the "top." In this case, it simply removed the first element.
I tried using a move function, as such:
items[Root()] = std::move(items[cur_size--]);
This should swap the root with another element, which it would then reorder (which also hasn't been working).
Instead, I tried something this:
std::vector<int> items;
int root = 0;
size_t Root() {
return root;
}
void Pop() {
items.erase(items.begin()+root);
root++;
// here I would call the reorder function
}
In this way I would effectively change the root and operate as if the vector started on the n-th position, rather than at 0.
My question is, does that make sense, or is there a better way I could be implementing this?
edit: added vector