IOS 快速排序法

- (NSMutableArray *)QuickSort:(NSMutableArray *)list StartIndex:(NSInteger)startIndex EndIndex:(NSInteger)endIndex
{
    if(startIndex < endIndex)
    {
        NSString * temp = [list objectAtIndex:startIndex];
        NSInteger tempIndex = startIndex; //临时索引 处理交换位置(即下一个交换的对象的位置)
        
        for(int i = (int)startIndex  ; i <= endIndex ; i++)
        {
            NSString *temp1 = [list objectAtIndex:i];
            if([temp intValue] > [temp1 intValue]){
                tempIndex = tempIndex + 1;
                [list exchangeObjectAtIndex:tempIndex withObjectAtIndex:i];
            }
        }
        
        [list exchangeObjectAtIndex:tempIndex withObjectAtIndex:startIndex];
        [self QuickSort:list StartIndex:startIndex EndIndex:tempIndex-1];
        [self QuickSort:list StartIndex:tempIndex+1 EndIndex:endIndex];

    }
    
    return list;
    
}
原文地址:https://www.cnblogs.com/joesen/p/3591966.html