IOSOC/C array of immutable variables

Source: Internet
Author: User

1. Review C Array sorting

int a[6] = {1,4,3,5,6,2};

Choose

for (int i =0; i<6-1; i++) {

for (int j = i+1; j<6;j++) {

if (A[i]>a[j]) {

int tmp = A[i];

A[i] = A[j];

A[J] = tmp;

}

}

}

for (int i=0;i<6;i++) {

printf ("a[%d] =%d\n", i,a[i]);

}

Nsarray sort

Nsarray * array = @[@ "1", @ "4", @ "5", @ "7", @ "2", @ "9"];

The current put-back value is an array, which is provided by default, and is not frequently used in compliance with limitations of small scale

[Array sortedarrayusingselector: @selector (compare:)];

[Array sortedarraywithoptions:<# (nssortoptions) #> Usingcomparator:<#^nscomparisonresult (ID obj1, id obj2 ) Cmptr#>]

[Array sortedarrayusingfunction:<# (Nsinteger (*) (__strong ID, __strong id, void *)) #> context:<# (void *) # ;]

Nsmutablearray * arr2 = [[Nsmutablearray Alloc]initwitharray:array];

for (int i = 0; i<[arr2 count]-1; i++) {

for (int j = i+1; j<[arr2 count]; j + +) {

if ([Arr2[i] intvalue]) > ([Arr2[j] intvalue]) {

NSString * str = arr2[i];

Arr2[i] = Arr2[j];

ARR2[J] = str;

}

}

}

NSLog (@ "%@", arr2);

IOSOC/C array of immutable variables

Related Article

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.