李振良Go/Golang DevOps運維開發(fā)實戰(zhàn)集訓(xùn)營
OC語言實現(xiàn):
- (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;}
?
標(biāo)簽: