For the assignment I need to make a custom vector class that can be used as the container for a queue where all assignments are O(1).
I'm trying to implement a pop_front function in my vector to do this, but it isn't working. Here's what I have for it.
Void pop_front(){
arr += sizeof(T);
siz--;
}
arr is a dynamically allocated array I'm using for the container, and siz is its current size. Is there something fundamentally wrong with what I'm trying to do?
1 Answer 1
I suppose that your array container is a class that will contain the size of your included elements. Simply knock off the first element by ignoring it! YOU control how the user accesses each element (through its index) with the operator[]() function, so after pop_front(), you change the way the array is accessed, in a way that ignores the first element through operator[]().
Simple enough? Hope so! It needs some work and some testing, but you can do it!
std::deque?pop_frontgenerally returns the value of the first element by the waypop*methods don't return a value.