现在的位置: 首页 > 综合 > 正文

数组的冒泡排序

2013年03月28日 ⁄ 综合 ⁄ 共 407字 ⁄ 字号 评论关闭

- (void)bubbleSort:(NSMutableArray *)array {

   
int i, y;

   
BOOL bFinish = YES;

   
for (i = 1; i<= [array
count] && bFinish; i++) {

        bFinish =
NO;

       
for (y = (int)[array
count]-1; y>=i; y--) {

           
PlateNumber *num1 = [array
objectAtIndex
:y];

           
PlateNumber *num2 = [array
objectAtIndex
:y-1];

           
if ([num1.number
intValue] < [num2.number
intValue]) {

                [array exchangeObjectAtIndex:y-1
withObjectAtIndex:y];

                bFinish =
YES;

            }

        }

    }

}

抱歉!评论已关闭.