#import <Foundation/Foundation.h>
@interface QuickSort : NSObject
/// 快速排序
+ (void)quickSortWithArray:(NSMutableArray *)array withLeft:(NSInteger)left andRight:(NSInteger)right;
@end
#import "QuickSort.h"
@implementation QuickSort
+ (void)quickSortWithArray:(NSMutableArray *)array withLeft:(NSInteger)left andRight:(NSInteger)right
{
if (left >= right) return;
NSInteger i = left;
NSInteger j = right;
NSInteger key = [array[left] integerValue];
while (i<j) {
while (i<j && key <= [array[j]integerValue]) {
j--;
}
array[i] = array[j];
while (i<j && key >= [array[i]integerValue]) {
i++;
}
}
array[j] = array[i];
[[self class]quickSortWithArray:array withLeft:left andRight:i -1];
[[self class]quickSortWithArray:array withLeft:i+1 andRight:right];
}
@end