开发者

Objective-c - Sort some Numbers stored is variables

开发者 https://www.devze.com 2023-03-09 13:57 出处:网络
hello开发者_如何学JAVA I want to sort(ascending) some numbers stored in different variables(like int a=50,int b=60, etc..)!

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

精彩评论

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