- (void)bubble_sort {
int i = [finalRouteList count]-1;
bool change = true;
for (; i>=1&&change; --i) {
change = false;
for (int j = 0; j Route *myRoute1 = [finalRouteList objectAtIndex:j];
Route *myRoute2 = [finalRouteList objectAtIndex:j+1];
AvegoAppDelegate *delegate = (AvegoAppDelegate *)[[UIApplication sharedApplication] delegate];
if ((pow([myRoute1.fromLat doubleValue]-delegate.locationManager.location.coordinate.latitude, 2)+pow([myRoute1.fromLon doubleValue]-delegate.locationManager.location.coordinate.longitude, 2))>(pow([myRoute2.fromLat doubleValue]-delegate.locationManager.location.coordinate.latitude, 2)+pow([myRoute2.fromLon doubleValue]-delegate.locationManager.location.coordinate.longitude, 2))){
[finalRouteList exchangeObjectAtIndex:j withObjectAtIndex:j+1];
change = true;
}
}
}
}
Search This Blog
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment