# reordering a vector from low to high

This topic is 3707 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Heya :D, Let me wish you all the best wishes for 2008 in advance, and then move onto my problem. I've got a std::vector with randomly ordered ints, and I'd like them to be ordered from low to high. I've found a way myself, but it seems rather timeconsuming and not clean. I was wondering if there were different ways, or if there isn't just a simple function (whether in the vector, or in de std itself) that'd do this for me. The solution I came up with was to go through the vector with a forloop, and check everytime you enter a new element if it's higher than the next. If so, swap 'em. Do this routine as many times as there are elements in your vector, and it should be ordered. Any better ideas, or is this indeed the way to go? -Stijn

##### Share on other sites
std::sort(vec.begin(),vec.end());

##### Share on other sites
std::sort. By the way, your implementation is technically known as bubble-sort.

Σnigma

Thanks mates!

[smile]