by Martin York <Martin.YorkAmazon@[EMAIL PROTECTED]
>
Apr 23, 2008 at 01:10 PM
> for (int j = 0; j < count; j++)
> {
> for (i = j+1; i < count; i++)
> {
> operations++;
> if (vector_in[i] < vector_in[j])
> {
> temp_int = vector_in[i];
> vector_in[i] = vector_in[j];
> vector_in[j] = temp_int;
> }
> }
> }
AKA: Bubble sort.
Sorting algorithms are measured in term of their complexity:
Bubble sort has a complexity of O(n^2)
In bubble sort, if you had an array of n elements, th sort requires
two nested loops that both basically iterate over the whole length of
the array (though you have tried to optimizeing this by limiting the
inner loop this does not affect the complexity) [PS your optimization
fails].
There are multiple sorts available (do a google on sorting
algorithms), The most optimal sort is called a bucket sort. Under
optimal conditions has a complexity of O(n).
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]