开发者

Objective-c - Sort some Numbers stored is variables

hello开发者_如何学JAVA I want to sort(ascending) some numbers stored in different variables(like int a=50,int b=60, etc..)! How can i do that? Thanks for any help!


You need to store the numbers in an NSArray, packaged in NSNumbers. Then you can do normal array sorting:

NSArray *array = [NSArray arrayWithObjects:
    [NSNumber numberWithInt:a],
    [NSNumber numberWithInt:b],
    nil
];

NSArray *sorted = [array sortedArrayUsingSelector:@selector(compare:)];


Put them into NSArray or NSMutableArray and sort the array

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜