I have multiple arrays of strings, I used a comparison function to sort them in a priority queue. I overlooked the fact that I need to iterate through the strings..
What other data structure would you recommend? Perhaps something that allows a comparison function so that I get a sorted set of strings
I could effectively pop the elements from the priority queue but that means I would need auxiliary space before pushing them back onto the priority queue
It would be ideal if a vector allows a comparison function. Would an STL “set” work? I have a fixed number of elements (about 450).
Edit: Confirming that STL’s set is working.. even without defining my own comparison function for strings.
A set would work, but you could just make a vector, reserve enough capacity, and then use sorted inserts using
lower_bound. Since strings are cheap to swap, this should be fine (and in any case 450 is a tiny number).A vector has constant-time lookup and random access, so if you don’t need to insert and erase a lot, it’s a better choice.