• Advertisement
Sign in to follow this  

Efficient way to sort only three values?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I know of several sorting methods, but my professor, in assigning the project, implied that there is an easy way to sort only three values, like a shortcut or whatnot. I know how I would do it using a bubble sort, but not of a better, more efficient way. This would only be for three values (not more or less). Any ideas? Thanks in advance. BTW, the general flow of the program is this (and can't be changed).
Quote:
sort(int &min, int &mid, int &max) { // sort and restore the values } int main() { //ask user for three values cin >> min >> mid >> max; sort(min,mid,max); }

Share this post


Link to post
Share on other sites
Advertisement
Gamedev is not the place to ask help on school assignments. Ask your professor or TA instead.

Sorting 3 elements can be done with two or three comparisons, depending on the actual values. Working it out by hand isn't difficult.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Guest
This topic is now closed to further replies.
Sign in to follow this  

  • Advertisement