zoukankan      html  css  js  c++  java
  • NSArray数组随机排序

    NSArray和NSMutableArray的区别是前者是不可变数组,一旦数组初始化完成以后,就只能对数组进行查询操作,而后者是可变数组,数组初始化完成以后,继而可以进行增、删、改、查操作。所以对于数组的乱序排序,必须要在可变数组中进行操作。具体代码如下:

    //数组随机排序

    - (NSMutableArray *) randomizedArrayWithArray:(NSArray *)array {

        NSMutableArray *results = [[NSMutableArrayalloc]initWithArray:array];

        int i = [results count];

        while(--i > 0) {

            int j = rand() % (i+1);

            [results exchangeObjectAtIndex:i withObjectAtIndex:j];

        }

        return [results autorelease];

    }

  • 相关阅读:
    next_permutation( ) 和prev_permutation( ) 全排列函数
    F
    STL入门
    H
    C
    提交按钮组件
    JScorllPane面板(带滚轮的JPane)
    JPanel画板
    网络布局管理器
    边界布局管理器
  • 原文地址:https://www.cnblogs.com/daguo/p/3107812.html
Copyright © 2011-2022 走看看