Sorting Variables

Have you got the greatest 48 bit multiplier ever conceived? Prove it - post your code here.

Moderator: phalanx

Post Reply
HappyBomberGuy
Posts: 24
Joined: Sat Mar 13, 2010 9:37 pm

Sorting Variables

Post by HappyBomberGuy » Thu Jun 02, 2011 1:34 pm

Anyone have a short code snippet or pseudocode for sorting variable values from low to high?

fll-freak
Support Volunteer
Posts: 1518
Joined: Tue May 12, 2009 8:23 am
Location: New Hampshire, USA
Contact:

Re: Sorting Variables

Post by fll-freak » Thu Jun 02, 2011 2:21 pm

How many values?
What language?
Looking to optimize speed or code size?

rmteo1
Posts: 294
Joined: Wed Mar 21, 2007 10:11 am

Re: Sorting Variables

Post by rmteo1 » Thu Jun 02, 2011 2:28 pm

Why use 8 bits when you can have 32?
ARM CORTEX Rules!!! :mrgreen: :mrgreen: :mrgreen:

HappyBomberGuy
Posts: 24
Joined: Sat Mar 13, 2010 9:37 pm

Re: Sorting Variables

Post by HappyBomberGuy » Thu Jun 02, 2011 11:59 pm

Only need to sort 3 variables from low to high, these will change each time through the program so I need to sort them each time. It will be in C.

Longhorn Engineer
Posts: 3
Joined: Sat Jun 11, 2011 10:31 pm
Location: Austin, Tx
Contact:

Re: Sorting Variables

Post by Longhorn Engineer » Sun Jun 19, 2011 12:26 am

qsort(A,sizeof(A),sizeof(int),compare);

Where A is the array that holds the variables and compare is this function.

int compare (const void * a, const void * b)
{
return ( *(int*)a - *(int*)b );
}

More info here. http://www.cplusplus.com/reference/clib ... lib/qsort/

Its in the stdlib of C so you should be fine.

Post Reply