• 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;
        
    }
  • 相关阅读:
    poj 2443
    codeforces 263D
    codeforces 263C
    uva 11080
    uva 11235
    uva 11748
    STL uva 11991
    (KM) uva 11383
    (树形DP) uva 10859
    codeforces 242C
  • 原文地址:https://www.cnblogs.com/joesen/p/3591966.html
Copyright © 2020-2023  润新知