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