If I have a std:queue
can I erase an element in the middle?
Or should I just go for a simple vector?
EDIT:
In the end, my search became between std::list
and std::deque
. this post gives a nice comparison, although I am still a bit undecided.
On one side, since after deletion I won't be accessing more members (the operation finishes) I am not that concerned about iterator invalidation. On the other side, I will probably access (or search) elements one by one, so random access might not be that important...
You can use an index that contain the position of each element, and after if you want delete an element you use his position v(i). There are a lot of method, dependig by your algorithms. If you need to perform operations on elements in the middle, you need a List, not a Queue.
pop() function is used to remove an element from the front of the queue(oldest element in the queue). This is an inbuilt function from C++ Standard Template Library(STL). This function belongs to the <queue> header file. The element is removed from the queue container and the size of the queue is decreased by 1.
The remove() method of PriorityQueue class removes a single instance of the specified element from this queue, only if it is present.
No, not unless you want to take all the elements out and put them back in again.
A std::list
might be better, but it depends on what else you want to do with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With