I am currently looking into how Vectors work in C++. I have read and understand their functionality pretty well.
I’m looking at different ways of sorting a vector object with 10,000 ints, I’ve used the std::sort method, and a shell sort.
I noticed that a shell sort for a vector is slower than sorting a simple C style array. I learnt this was because “Fast element insertion or removal in the middle of the container is not supported” (http://www.cppreference.com/wiki/container/vector/start). So obviously a shell sort with lots of random accesses is going to be quite slow.
I was wondering in anyones experience what a better manual sorting method would be for a vector with 10,000 ints? This is for a learning exercise you see! 🙂
Try the quickselect or quicksort algorithms (very similar but depends on what you need). In any case, these are just relatively simple and popular algorithms – more importantly, in practice they are fast (although they do have bad worst cases).
Regards,
Dennis M.