算法

2017-03-07  本文已影响7人  onlyyourself

//冒泡排序从大到小

//冒泡排序从小到大

//快速排序

}

//选择排序

//直接插入排序

//二分插入排序

//希尔排序
-(void)shellSort:(NSMutableArray *)mArray {
int gap = (int)[mArray count] / 2;
while (gap >= 1) {
for(int i = gap ; i < [mArray count]; i ++){
int temp = [[mArray objectAtIndex:i] intValue];
int j = i;
while (j >= gap && temp < [[mArray objectAtIndex:(j - gap)] intValue]) {
[mArray replaceObjectAtIndex:j withObject:[mArray objectAtIndex:j-gap]];
j -= gap;
}
[mArray replaceObjectAtIndex:j withObject:[NSNumber numberWithInt:temp]];
}
gap = gap / 2;
}
}

//堆排序(目前不支持负数)

上一篇下一篇

猜你喜欢

热点阅读