Sign in to follow this  
stenny

reordering a vector from low to high

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 this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this