IOS Array Sort Instance

Source: Internet
Author: User
<span id="Label3"></p><p><p>IOS Array Sorting<br><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;"><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;">Nsmutablearray *p = [[nsmutablearray alloc] initwithobjects:@ "S1", @ "S14", @ "S3", @ "S4", @ "S12", @ "S6", @ "S7", @ "S8", @ "S9" , @ "S10", @ "S11", @ "S5", @ "S13", @ "S2", nil];<br><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;">Answer: (compare Who's method is simple, Efficient)<br></span></span></span></p></p><p><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;"><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;"><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;">Nsmutablearray *p = [[nsmutablearray alloc] initwithobjects:@ "S1", @ "S14", @ "S3", @ "S4", @ "S12", @ "S6", @ "S7", @ "S8", @ "S9" , @ "S10", @ "S11", @ "S5", @ "S13", @ "S2", nil];<br><br>[p sortusingcomparator:^nscomparisonresult (id obj1, ID obj2) {<br>NSString *a = (nsstring *) obj1;<br>NSString *b = (nsstring *) obj2;<br><br>int anum = [[a substringfromindex:1] intvalue];<br>int bnum = [[b substringfromindex:1] intvalue];<br><br>If (anum > Bnum) {<br>Return nsordereddescending;<br>}<br>else if (anum < Bnum) {<br>Return nsorderedascending;<br>}<br>else {<br>Return nsorderedsame;<br>}<br>}];<br><br><br>NSLog (@ "p%@", p);</span></span></span></p><code style="outline: 0px !important; margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, ‘Bitstream Vera Sans Mono‘, ‘Courier New‘, Courier, monospace !important; font-size: 1em !important; min-height: inherit !important;"><code style="outline:0px!important; margin:0px!important; padding:0px!important; border-top-left-radius:0px!important; border-top-right-radius:0px!important; border-bottom-right-radius:0px!important; border-bottom-left-radius:0px!important; background-image:none!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; box-sizing:content-box!important; font-family:consolas, ' bitstream Vera Sans Mono ', ' Courier New ', Courier, monospace!important; font-size:1em!important; min-height:inherit!important; "></code></code><code style="outline: 0px !important; margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, ‘Bitstream Vera Sans Mono‘, ‘Courier New‘, Courier, monospace !important; font-weight: bold !important; font-size: 1em !important; min-height: inherit !important; color: #006699 !important;"><code style="outline:0px!important; margin:0px!important; padding:0px!important; border-top-left-radius:0px!important; border-top-right-radius:0px!important; border-bottom-right-radius:0px!important; border-bottom-left-radius:0px!important; background-image:none!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; box-sizing:content-box!important; font-family:consolas, ' bitstream Vera Sans Mono ', ' Courier New ', Courier, monospace!important; font-weight:bold!important; font-size:1em!important; min-height:inherit!important; Color: #006699!important; "></code></code><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;"><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;"><code style="white-space: pre; font-size: 1em !important; outline: 0px !important; margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, ‘Bitstream Vera Sans Mono‘, ‘Courier New‘, Courier, monospace !important; min-height: inherit !important;"><code style="white-space: pre; font-size: 1em !important; outline: 0px !important; margin: 0px !important; padding: 0px !important; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 0px !important; border-bottom-left-radius: 0px !important; background-image: none !important; border: 0px !important; bottom: auto !important; float: none !important; height: auto !important; left: auto !important; overflow: visible !important; position: static !important; right: auto !important; top: auto !important; vertical-align: baseline !important; width: auto !important; box-sizing: content-box !important; font-family: Consolas, ‘Bitstream Vera Sans Mono‘, ‘Courier New‘, Courier, monospace !important; min-height: inherit !important;"></code></code><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;"><span style="color: #333333; font-family: ‘Helvetica Neue‘, Helvetica, STheiti, 微软雅黑, 黑体, Arial, Tahoma, sans-serif, serif;"><br></span></span></span></span><p><p>IOS Array Sort Instance</p></p></span>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.