Last active
December 27, 2015 09:49
-
-
Save youweit/7306258 to your computer and use it in GitHub Desktop.
Quick sort
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Call with [self quickSort:0 withHigh:[scanpleFileList count]-1]; | |
-(void)quickSort:(int)low withHigh:(int)high;{ | |
int i = low,j = high; | |
int pivot = [[[scanpleFileList objectAtIndex:(low+high)/2]time]intValue]; | |
while(i <= j){ | |
while([[[scanpleFileList objectAtIndex:i]time]intValue] < pivot) i++; | |
while([[[scanpleFileList objectAtIndex:j]time]intValue] > pivot) j--; | |
if(i<=j){ | |
[scanpleFileList exchangeObjectAtIndex:i withObjectAtIndex:j]; | |
i++; | |
j--; | |
} | |
} | |
if(low < j) [self quickSort:low withHigh:j]; | |
if(i < high)[self quickSort:i withHigh:high]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment