hi, I have been writing a football tournament simulator and I am almost done, however i need to some how sort the teams after a round the put the teams that progress into the next round. The data of the teams is held in structures and have a boolean vale, progress, which should be false unless your team progresses. I have 8 teams and I need to find the top 4, I have the code in place to change the booleans to true or false but I now need a way to send these teams into a function without a huge block of if statements. Any ideas would be much appreciated.

Cheers
Dan

You can use std::sort() or std::partition().

would you be able to trow together a short example, nothing fancy, just a quick once over to give a breif outline of how to use it

>>I have 8 teams and I need to find the top 4,

You don't really need to sort because all you care for is the top 4 team. In fact if you were using the correct data structure, you wouldn't need to worry about picking the top 4 teams, for example using graphs. But I assume your doing something easier like using a vector of structures? You can either sort,partition,or simply find the max 4 times.

I usually use self-sorting structures so that when an item is added to the list, it is automatically sorted. Getting data out in a sorted manner is then trivial - just walk the list, so to speak.

This article has been dead for over six months. Start a new discussion instead.