仅用来记录算法学习笔记,纯手打,不喜勿喷
冒泡排序
//冒泡排序
NSMutableArray *array = [NSMutableArray arrayWithArray:@[@"6",@"5",@"4",@"3",@"2",@"1",@"0"]] ;
for (int x = 0; x [array[i+1] intValue]) {
j = array[i];
array[i] = array[i+1];
array[i+1] = j;
}
}
}
NSLog(@"array==%@",array);
输出结果为
2020-04-16 10:29:42.577734+0800 KaadasLock[2940:636672] array==(
0,
1,
2,
3,
4,
5,
6
)
选择排序法
NSMutableArray *arrays = [NSMutableArray arrayWithArray:@[@"6",@"5",@"4",@"3",@"2",@"1",@"0"]];
for (int j = 0; j [arrays[i] intValue]) {
x= i;
}
id tmp = arrays[j];
arrays[j] = arrays[x];
arrays[x] = tmp;
}
}
NSLog(@"arrays[] ===%@",arrays);
输出结果为
2020-04-16 19:13:52.560757+0800 ALPHA LOCK ACCESS[3518:789724] arrays[] ===(
0,
1,
2,
3,
4,
5,
6
)