#import <Foundation/Foundation.h>
@interface ShellSort : NSObject
/**
希尔排序
@param list 被排序的数组
*/
+ (void)shellSort:(NSMutableArray *)list;
@end
#import "ShellSort.h"
@implementation ShellSort
+ (void)shellSort:(NSMutableArray *)list{
int gap = [list count]/2.0;
while (gap>=1) {
for(int i =0;i<[list count];i++){
NSInteger temp = [[list objectAtIndex:i] integerValue];
int j =i;
while (j>=gap && temp <[[list objectAtIndex:(j-gap)] integerValue]) {
[list replaceObjectAtIndex:j withObject:[list objectAtIndex:j-gap]];
j-=gap;
}
[list replaceObjectAtIndex:j withObject:[NSNumber numberWithInteger:temp]];
}
}
}
@end