Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@youweit
Last active December 27, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youweit/7306258 to your computer and use it in GitHub Desktop.
Save youweit/7306258 to your computer and use it in GitHub Desktop.
Quick sort
//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