- #import <Foundation/Foundation.h>
- int main(int argc, const charchar * argv[]) {
- @autoreleasepool {
- //原始数组
- NSMutableArray *originalarray = [NSMutableArray arrayWithArray:@[@1, @3, @5, @7, @9]];
- int inputnumber;
- scanf("%d",&inputnumber);
- for (int i=0; i<originalarray.count; i++) {
- if ([[NSNumber numberWithInt:inputnumber]compare:originalarray[i]]<0) {
- [originalarray insertObject:[NSNumber numberWithInt:inputnumber] atIndex:i];
- break;
- }
- if (i==originalarray.count) {
- [originalarray insertObject:[NSNumber numberWithInt:inputnumber] atIndex:originalarray.count];
- }
- }
- NSLog(@"%@",originalarray); //打印
- }
- return 0;
- }
转载于:https://www.cnblogs.com/xzz5211314/p/5127702.html