zoukankan      html  css  js  c++  java
  • 集合

    #import <Foundation/Foundation.h>
    
    int main(int argc, const char * argv[]) {
        @autoreleasepool {
            //初始化NSSet
            NSSet *set1=[NSSet set];
            NSSet *set2=[NSSet setWithObjects:@"jack",@"yang",nil];
            //获取NSSet中数据的个数
            NSInteger count=[set2 count];
            //随机取出NSSet中的元素
            NSString *str=[set2 anyObject];
            //通过数组创建集合
            NSArray *arr=[NSArray arrayWithObjects:@"a",@"b",@"c",@"d",@"a",nil];
            NSSet *set3=[NSSet setWithArray:arr];
            //判断集合中是否包含
            BOOL bo1=[set3 containsObject:@"b"];
            //判断两个集合是否含有相同元素
            BOOL bo2=[set2 intersectsSet:set3];
            //集合1是否是集合2的子集
            BOOL bo3=[set1 isSubsetOfSet:set2];
            //NSMutableSet
            NSMutableSet *mSet1=[NSMutableSet setWithObjects:@"1",@"2",@"3",@"4", nil];
            NSMutableSet *mSet2=[NSMutableSet setWithObjects:@"a",@"2", nil];
            NSMutableSet *mSet3=[NSMutableSet set];
            //集合1减去集合2
            //[mSet1 minusSet:mSet2];
            //集合1与集合2交集(mSet1元素改变,mSet2不变)
            //[mSet1 intersectSet:mSet2];
            //集合1与集合2并集(mSet1元素改变,mSet2不变)
            [mSet1 unionSet:mSet2];
            //移除集合中的元素
            [mSet1 removeObject:@"2"];
        }
        return 0;
    }
    
  • 相关阅读:
    SD卡测试
    测试人员可能会遇到的问题
    HDU 1024 Max Sum Plus Plus
    HDU 1176 免费馅饼
    HDU 1257 最少拦截系统
    HDU 1087 Super Jumping! Jumping! Jumping!
    poj 1328 Radar Installation
    poj 1753 Flip Game
    HDU 1003 Max Sum
    HDU 5592 ZYB's Premutation(BestCoder Round #65 C)
  • 原文地址:https://www.cnblogs.com/hezhuangzhuang/p/5121103.html
Copyright © 2011-2022 走看看