Selection Sort in Object C
-(void)SelectionSort{
NSMutableArray *dataA = [NSMutableArray arrayWithArray:@[@15,@58,@33,@41,@28,@14]];
int max;
for (int i = 0; i< dataA.count - 1; i++) {
max = i;
for (int j = i +1 ; j < dataA.count ; j++){
if ([[dataA objectAtIndex:j] intValue] > [[dataA objectAtIndex:max] intValue]) {
max = j;
}
}
[dataA exchangeObjectAtIndex:i withObjectAtIndex:max];
}
NSLog(dataA);
}
0 comments: