数组排序-冒泡法

//
//  main.m
//  作业3
//
//  Created by syrcfwzx on 16/1/6.
//  Copyright (c) 2016年 syrcfwzx. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
    
        NSMutableArray* array = [[NSMutableArray alloc]initWithObjects:@"114",@"159",@"220",@"100", nil];
        for(int i= 0;i<[array count];i++)
        {
            for(int j=0;j<[array count]-i-1;j++)
            {
                NSString* p =[array objectAtIndex:j];
                NSString* q =[array objectAtIndex:j+1];
                if([p intValue]>[q intValue])
                {
                    [array exchangeObjectAtIndex:j withObjectAtIndex:j+1];
                }
            }
            
        }
        NSLog(@"%@",array);
        
    }
    return 0;
}
原文地址:https://www.cnblogs.com/hezhuangzhuang/p/5115476.html