Combined Sorting Algorithm in oc and oc combined Sorting Algorithm
-(NSMutableArray *) zuHeSuanFa :( NSMutableArray *) array chooseCount :( int) m {int n = (int) [array count]; if (m> n) {return nil ;} // NSLog (@ "a combination of % d numbers from 1 to % d... ", N, m); NSMutableArray * allChooseArray = [[NSMutableArray alloc] init]; NSMutableArray * retArray = [array copy]; // (1, 1, 0, 0) for (int I = 0; I <n; I ++) {if (I <m) {[array replaceObjectAtIndex: I withObject: @ "1"];} else {[array replaceObjectAtIndex: I withObject: @ "0"] ;}} NSMutableArray * firstArray = [[NSMutableArray alloc] init]; for (int I = 0; I <n; I ++) {if ([[array objectAtIndex: I] intValue] = 1) {// [firstArray addObject: [NSString stringWithFormat: @ "% d ", I + 1]; [firstArray addObject: [retArray objectAtIndex: I]; // NSLog (@ "% d", I + 1);} [allChooseArray addObject: firstArray]; // [firstArray release]; // NSLog (@ "=============="); int count = 0; for (int I = 0; I <n-1; I ++) {if ([array objectAtIndex: i] intValue] = 1 & [[array objectAtIndex :( I + 1)] intValue] = 0) {[array replaceObjectAtIndex: I withObject: @ "0"]; [array replaceObjectAtIndex :( I + 1) withObject: @ "1"]; // I = 2, (1, 1, 1, 0) for (int k = 0; k <I; k ++) {if ([[array objectAtIndex: k] intValue] = 1) {count ++ ;}} if (count> 0) {for (int k = 0; k <I; k ++) {if (k <count) {// k = 1, (1, 1, 1, 0) [array replaceObjectAtIndex: k withObject: @ "1"];} else {[array replaceObjectAtIndex: k withObject: @ "0"] ;}} NSMutableArray * middleArray = [[NSMutableArray alloc] init]; for (int k = 0; k <n; k ++) {if ([array objectAtIndex: k] intValue] = 1) {// NSLog (@ "% d", k + 1); // [middleArray addObject: [NSString stringWithFormat: @ "% d ", k + 1]; [middleArray addObject: [retArray objectAtIndex: k] ;}} [allChooseArray addObject: middleArray]; // [middleArray release]; // NSLog (@ "=============="); I =-1; count = 0 ;}} return allChooseArray ;}