- #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;
- }
在数组中添加一个元素 数组顺序依旧正常排序
原文:http://www.cnblogs.com/xzz5211314/p/5127702.html