I have two arrays. Let\'s say:
array = \"Dave\", \"Mike\", \"Joe\", \"Jason\", \"Kevin\"
and
IQ = 110, 145, 75, 122, 130
Construct a 2d array with first row as names and second row as IQ Sort this array according to the IQ in O(nlogn)
This would be a better way to make a dictionary for users. And then sorting based on their specific values like IQ, Name etc.
NSArray *users = @[@"Dave",@"Mike",@"Joe",@"Jason",@"Kevin"];
NSArray *iqs = @[@110,@145,@75,@122,@130];
NSMutableArray *array = [NSMutableArray array];
for (int idx = 0;idx<[users count];idx++) {
NSDictionary *dict = @{@"Name": users[idx],@"IQ":iqs[idx]};
[array addObject:dict];
}
NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"IQ" ascending:NO];
[array sortUsingDescriptors:@[descriptor]];