-
+(NSMutableArray *)kuaisuMethodTest:(NSMutableArray *)dataArray low:(int )lowIndex high:(int)highIndex{
-
// NSMutableArray *data=[[NSMutableArray alloc] initWithObjects:@"5",@"4",@"2",@"8",@"1",@"7",@"9",@"6",nil];
-
if (lowIndex<highIndex) {
-
int i=lowIndex,j=highIndex;
int vot=[[dataArray objectAtIndex:i] intValue];
while (i!=j) {
while (i<j && vot<=[[dataArray objectAtIndex:j] intValue]) j--;
NSLog(@"j=======%d",j);
-
if (i<j) {
-
[dataArray replaceObjectAtIndex:i withObject:[dataArray objectAtIndex:j]];
NSLog(@"i=======[dataArray objectAtIndex:%d]=====%@",i,[dataArray objectAtIndex:i]);
-
i++;
-
}
while (i<j && [[dataArray objectAtIndex:i] intValue]<vot) i++;
if (i<j) {
[dataArray replaceObjectAtIndex:j withObject:[dataArrayobjectAtIndex:i]];
-
NSLog(@"j======[dataArray objectAtIndex:%d]=====%@",j,[dataArray objectAtIndex:j]);
-
j--;
-
}
-
}
-
[dataArray replaceObjectAtIndex:i withObject:[NSString stringWithFormat:@"%d",vot]];
-
NSLog(@"low:(%d)....high:(%d)....vot:(%d)...%@",lowIndex,highIndex,vot,dataArray);
-
[AppDelegate kuaisuMethodTest:dataArray low:lowIndex high:j-1];//前端子序列再排序
-
[AppDelegate kuaisuMethodTest:dataArray low:i+1 high:highIndex];//后端子序列再排序
-
}
-
return dataArray;
-
}
转载于:https://www.cnblogs.com/guangzhi405/archive/2012/08/13/2636852.html