用OC语法实现冒泡排序

 1         NSMutableArray *arrM = [NSMutableArray arrayWithObjects:@"5", @"6", @"7", @"3", @"4", nil];
 2         
 3         NSUInteger count = arrM.count;
 4         for (NSUInteger i = 0; i < count; i++) {
 5             for (NSUInteger j = i+1; j < count; j++) {
 6                 int a = [arrM[i] intValue];
 7                 int b = [arrM[j] intValue];
 8                 if (a < b) {
 9                     arrM[i] = [NSString stringWithFormat:@"%d", b];
10                     arrM[j] = [NSString stringWithFormat:@"%d", a];
11                 }
12             }
13         }
14         NSLog(@"%@",arrM);    

 

posted @ 2015-03-12 14:33  iNano  阅读(753)  评论(0编辑  收藏  举报