NSArray *persons = @[
@{@"name" : [s1 name],
@"age" :[NSNumber numberWithInt:[s1 age]],
@"grade":[NSNumber numberWithInt:[s1 garde]]},
@{@"name" : [s2 name],
@"age" :[NSNumber numberWithInt:[s2 age]],
@"grade":[NSNumber numberWithInt:[s2 garde]]},
@{@"name" : [s3 name],
@"age" :[NSNumber numberWithInt:[s3 age]],
@"grade":[NSNumber numberWithInt:[s3 garde]]},
@{@"name" : [s4 name],
@"age" :[NSNumber numberWithInt:[s4 age]],
@"grade":[NSNumber numberWithInt:[s4 garde]]},
@{@"name" : [s5 name],
@"age" :[NSNumber numberWithInt:[s5 age]],
@"grade":[NSNumber numberWithInt:[s5 garde]]},
];
for (int i = 0; i < persons.count; i++) {
for (int j = 0; j < persons.count - i -1; j++) {
id temp = nil;
if (persons[j][@"grade"] >persons[j+1][@"grade"] ) {
temp=persons[j+1][@"grade"];
persons[j+1][@"grade"]=persons[j][@"grade"];
persons[j][@"grade"]=temp;
}
}
} |
|