I've written some method for sorting asc and desc numbers in array. All I want to know is this good logic, and is there a space for improving this code?
-(NSArray *)sortHanded:(NSArray *)inputArray ascending:(BOOL)ascending {
NSMutableArray *inputMutableArray = [inputArray mutableCopy];
NSMutableArray *sortedArray = [NSMutableArray new];
NSNumber *min;
NSNumber *max;
if (ascending == YES) {
//starting while
while (inputMutableArray.count > 0) {
//starting switch
switch (inputMutableArray.count) {
//case 0
case 0:
break;
//case 1
case 1:
[sortedArray addObject:[inputMutableArray objectAtIndex:0]];
[inputMutableArray removeObject:[inputMutableArray objectAtIndex:0]];
break;
//starting default switch
default:
for (NSNumber *temp in inputMutableArray) {
if (min == nil) {
min = temp;
}
if (min > temp) {
min = temp;
}
}
[sortedArray addObject:min];
[inputMutableArray removeObject:min];
min = nil;
break;
//end default
//end start switch
}
//ending while
}
}
else {
//starting while
while (inputMutableArray.count > 0) {
//starting switch
switch (inputMutableArray.count) {
//case 0
case 0:
break;
//case 1
case 1:
[sortedArray addObject:[inputMutableArray objectAtIndex:0]];
[inputMutableArray removeObject:[inputMutableArray objectAtIndex:0]];
break;
//starting default switch
default:
for (NSNumber *temp in inputMutableArray) {
if (max == nil) {
max = temp;
}
if (max < temp) {
max = temp;
}
}
[sortedArray addObject:max];
[inputMutableArray removeObject:max];
max = nil;
break;
//end default
//end start switch
}
//ending while
}
}
//returning sorted array
return sortedArray;
}