IOS按照第一个字符排序

2016-09-03  本文已影响66人  蜗牛1992
/*按照第一个字符排序*/
-(NSMutableArray*) SortAsFirstChar:(NSMutableArray*)pFriendListArray
{
    NSMutableArray* pArray = [[NSMutableArray alloc] init];
    while(pFriendListArray.count > 0)
    {
        NSString* pName = ((UserFriendItem*)[pFriendListArray objectAtIndex:0])->pstrName;
        for(int i = 0;i < pFriendListArray.count; ++i)
        {
            if(NSOrderedSame == [((UserFriendItem*)[pFriendListArray objectAtIndex:i])->pstrName compare:pName])
            {
                [pArray addObject:[pFriendListArray objectAtIndex:i]];
            }
        }
        
        while(true)
        {
            int i = 0;
            for(;i < pFriendListArray.count; ++i)
            {
                if(NSOrderedSame == [((UserFriendItem*)[pFriendListArray objectAtIndex:i])->pstrName compare:pName])
                {
                    [pFriendListArray removeObjectAtIndex:i];
                    break;
                }
            }
            
            if(i == pFriendListArray.count)
            {
                break;
            }
        }
    }
    
    return pArray;
}
上一篇下一篇

猜你喜欢

热点阅读