taiyang2014

选择排序

    //选择排序  思想: 每次选择当前序列中的最大值
    NSMutableArray *sortSelect = [NSMutableArray arrayWithObjects:@12, @25, @0, @31, @20, nil];
    
    int m,n;
    NSNumber *temp;
    for (m = 0; m < sortSelect.count - 1; m++) {
        for (n = m + 1; n < sortSelect.count; n++) {
            if (sortSelect[n] < sortSelect[m]) {
                temp = sortSelect[n];
                sortSelect[n] = sortSelect[m];
                sortSelect[m] = temp;
            }
        }
    }
    
    for (NSNumber *num in sortSelect) {
        NSLog(@"%@", num);
    }

 

posted on 2015-02-03 20:36  taiyang2014  阅读(114)  评论(0编辑  收藏  举报

导航