# c oc swift的冒泡排序

关于  C 语音的冒泡排序

<span style="color:#000000;">    <span style="font-size:18px;color:#009900;"><span style="font-size:18px;color:#009900;"></span></span></span><pre name="code" class="objc">    //对一个数组排序
int array[10]={2,8,5,4,6,7,9,0,6,3}; for (int i = 0; i<10; i++) { for (int j = 0; j< 9; j++) { if (array[j]>array[j+1]) { int temp = 0; temp = array[j]; array[j] = array[j+1]; array[j+1] = temp; } } } for (int i = 0; i<10; i++) printf("%d\n",array[i]); };

关于 OC 语音的冒泡排序

    <span style="color:#000000;">//对一个数组排序
NSMutableArray *array = [[NSMutableArray alloc]init];
for (int i = 0;i<[array count]; i++) {
for (int j = 0; j< [array count] - 1; j++) {
if ([array[j] integerValue] > [array[j+1] integerValue]) {
int a = [[array objectAtIndex:i] intValue];
int b = [[array objectAtIndex:j] intValue];
if (a>b) {
[array replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%d",b]];
[array replaceObjectAtIndex:j withObject:[NSString stringWithFormat:@"%d",a]];
}
}
}
for (int i = 0; i<[array count]; i++)
NSLog(@"%@",[array objectAtIndex:i]);
}</span>


关于  Swift  语音的冒泡排序

<span style="font-size:18px;">var array = [2,8,5,4,6,7,9,0,6,3]
for var i = 0; i < array.count - 1; ++i {
for var j = 0; j < array.count - 1 - i; ++j{
if array[j] > array[j + 1] {
let temp = array[j + 1]
array[j + 1] = array[j]
array[j] = temp
}
}
}
print("排序后的值：")
for item in array
{
let a = item
print(a)
}</span>

• 本文已收录于以下专栏：

举报原因： 您举报文章：c oc swift的冒泡排序 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)