Bubble sort in IOS (OC)

Source: Internet
Author: User

Nsmutablearray *array = [Nsmutablearray arraywithobjects:@ "," @ "," @ "," @ "," @ "," @ "," @ ", nil];        Nsinteger count = [array count]; for (int i = 0, i < count; i++) {for (int j = 0; J < count-i-1, j + +) {//if ([[[Array                OBJECTATINDEX:J] intvalue] > [[Array Objectatindex: (j + 1)] intvalue]) {//here must be objectatindex:j when using [array intvalue//] if ([[[[Array objectatindex:j] Compare:[array Objectatindex:j + 1]] = =-1) {//The whole must have a return value, -1,0,1, because the return value of compare Nscomparisonresult is a value of an enumeration type, so return a value if ([[Arra                     Y Objectatindex:j] Compare:[array objectatindex:j + 1] options:nsnumericsearch] = = 1) {//Ibid. potions Nsnumericsearch = 64,  [Array exchangeobjectatindex:j Withobjectatindex: (j + 1)];                Here you can use the Exchangeobjectatindex: method to exchange two-position array elements.        }}} for (NSString *i in array) {NSLog (@ "%@", I); } NsmutableaRray *array1 = [Nsmutablearray arraywithobjects:@ "," @ "," @ "," @ "," @ "," @ "," @ ", nil];        [Array1 sortusingselector: @selector (compare:)];          NSLog (@ "%@", array);

Bubble sort in IOS (OC)

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.