李振良Go/Golang DevOps运维开发实战集训营
OC语言实现:
- (NSArray *)selectAlgorithm:(NSArray *)array{
NSMutableArray *tempArray = [NSMutableArray arrayWithArray:array];
NSInteger count = tempArray.count;
int index;
for (int i = 0; i < count - 1; i ++) {
index = i;
for (int j = i + 1; j < count; j ++) {
if (tempArray[index] > tempArray[j]) {
index = j;
}
}
if (index != i) {
id temp = tempArray[i];
[tempArray replaceObjectAtIndex:i withObject:tempArray[index]];
[tempArray replaceObjectAtIndex:index withObject:temp];
}
}
return tempArray;}