冒泡选择排序
Posted guligei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了冒泡选择排序相关的知识,希望对你有一定的参考价值。
NSMutableArray *mArray = [NSMutableArray arrayWithObjects:@4,@5,@9,@2,@3,@3,@2,@7, nil];
for (int i = 0; i<mArray.count-1; i++) {
for (int j = 0; j<mArray.count - i-1; j++) {
if (mArray[i] < mArray[i+1]) {
NSInteger temp = [mArray[i+1]integerValue];
mArray[i+1] = mArray[i];
mArray[i] = [NSNumber numberWithInteger:temp];
}
}
}
for (int i = 0; i<mArray.count-1; i++) {
for (int j = 0; j<mArray.count - i-1; j++) {
if (mArray[j] < mArray[j+1]) {
NSInteger temp = [mArray[j+1]integerValue];
mArray[j+1] = mArray[j];
mArray[j] = [NSNumber numberWithInteger:temp];
}
}
}
for (int i = 0; i<mArray.count-1; i++) {
for (int j = i; j<mArray.count-1; j++) {
if (mArray[j]<mArray[j+1]) {
NSInteger temp = [mArray[j+1]integerValue];
mArray[j+1] = mArray[j];
mArray[j] = [NSNumber numberWithInteger:temp];
}
}
}
for (int i = 0; i<mArray.count-1; i++) {
for (int j = i; j<mArray.count-1; j++) {
if (mArray[i]<mArray[j+1]) {
NSInteger temp = [mArray[j+1]integerValue];
mArray[j+1] = mArray[i];
mArray[i] = [NSNumber numberWithInteger:temp];
}
}
}
[mArray enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
NSLog(@"value %@",obj);
}];
以上是关于冒泡选择排序的主要内容,如果未能解决你的问题,请参考以下文章