/**
* sort from small to large
*
* @param left 0
* @param The number of right arrays
*/
-(void) Fastsortleftindex: (nsinteger) left Withrightindex: (nsinteger)right
{
Nsinteger I, J;
if(left > right) return;
nsinteger Tempmodel = [self. Dataarr[left] integervalue]; // benchmark model
i = left;
j = right;
while (i! = j) {
// starting from the right to find a model with a smaller score than the benchmark model
while (i<j && [self. Dataarr[j] IntegerValue]>tempmodel) {
j--;
}
// find from left to right
while (i < J && [self. Dataarr[i] integervalue] <= tempmodel) {
i++;
}
// If both sides have found the Exchange model
If(i < j)
{
nsinteger model_i = [self. Dataarr[i] integervalue];
nsinteger Model_j = [self. Dataarr[j] IntegerValue];
[self. Dataarr replaceobjectatindex: I withobject:@ (model_j)];
[self. Dataarr replaceobjectatindex: J withobject:@ (model_i)];
}
}
// If it meets
self. Dataarr[Left] = self. Dataarr[i];
self. Dataarr[i] = @ (tempmodel);
// After the end of the first round, the recursive - dichotomy method is used
[self fastsortleftindex: Left withrightindex:-1];
[self fastsortleftindex: i+1 withrightindex: right];
return;
// Quick Sort time complexity : N * Logn- So I prefer a quick sort of .
}
Quick Sort method from small to large