Sunday, September 30, 2012

Objective C InsertionSort


-(NSMutableArray*)InsertionSort:(NSMutableArray*)array
{
    for(int j=1;j< [array count];j++)
    {
        id key = [array objectAtIndex:j];
            int i =j-1;
     
       while (i>-1 && [array objectAtIndex:i] > key) {
                [array replaceObjectAtIndex:i+1 withObject:[array objectAtIndex:i]];
                i=i-1;
            }
        [array replaceObjectAtIndex:i+1 withObject:key];
    }
    return  array;
}

No comments:

Post a Comment