Let's say I need a queue for my project and the language I use does not have a built-in queue structure. So I decided to implement one myself. So I create an object with elements positions as the object's keys. I also keep track of where the head and the tail of my queue are. I increment and decriment those values when I enqueue and dequeue. Also when I dequeue I need to make sure the tail won't be before the head. And all that.
So will it be more efficient than using built-in arrays? Yeah, I know deleting athe first element of an array is pretty expensive in terms of efficiency. But usually languages provide a pretty good optimization for built-in structures.
And same question for the linked lists. Let's say I need to delete and insert elements in the middle of an array pretty often. Would creating a custom linked list, storing every element as an object with pointers, redirecting those pointers, keeping track of the head and the tail and all that... is it still better than using built-in and optimized arrays?
With that being said, which is a better solution? And how do I know when I need to choose the other option (like switching from built-in array to custom queue)? Maybe after certain amount of elements?
std::unordered_map
with a custom hashmap by exploiting relevant properties of my data.