Sorting Question

Good day,

Here's a question related to which container is better in a particular case:

Why is it more expensive to use a vector than a list when I intend to sort its elements ?

I just don't understand this theoretical matter.

Thanks in advance,

Jose
A vector has all it's elements stored sequentially in memory, like an array, so re-arranging them requires a lot of copies. A list has pointers to the next element in the list, so re-arranging those elements just requires a pointer assignment, which is much faster.
Got it !

ok, I had a brief notion in which I thought it was due to pointers that this type of operation would be faster. thanks for giving me a more detailed explanation.

Thank you, Thank you, Thank you, Thank you.

See you later.
Thank you, it helped me too.

See you late
Topic archived. No new replies allowed.