冒泡排序

来源:互联网 发布:淘宝延时喷剂是真的吗 编辑:程序博客网 时间:2024/06/14 00:56

NSMutableArray *array = [NSMutableArray arrayWithArray:@[@"3",@"1",@"10",@"5",@"2",@"7",@"12",@"4",@"8"]];

   for (int i =0; i < array.count; i ++) {

       for (int j =0; j < array.count  - 1 - i; j++) {

           if([[array objectAtIndex:j] integerValue] > [[array objectAtIndex:j +1] integerValue]) {

                [array exchangeObjectAtIndex:j withObjectAtIndex:j +1];

            }

        }

    }

    NSLog(@"%@", array);

0 0