Cel C: Sortowanie dwuwymiarowej tablicy
Mam tablicę tablic. Pierwszymi elementami zawartymi w tablicy są wszystkie obiekty NSDate. Chciałbym posortować tablicę zawierającą tablice w kolejności od najnowszej do najmniejszej. Z jakiegoś powodu poniższy algorytm sortowania powoduje nieskończoną pętlę. Czy ktoś może mi pomóc? Dziękuję Ci.
Najlepsza ... SL
//array is the array containing all of the other arrays(that have NSDates as their first elements)
//temp is the new array being added to the end of the array, to later be sorted into the correct position.
[array addObject:temp];
NSMutableArray *tempArray;
for (int i=0; i<[array count]; i++)
{
NSDate *session1, *session2;
session1 = [[array objectAtIndex:i] objectAtIndex:0];
session2 = [[array objectAtIndex:[array count]-1] objectAtIndex:0];
if([session1 compare:session2] == NSOrderedDescending)
{
tempArray = [array objectAtIndex:i];
[array insertObject:[array objectAtIndex:[array count]-1] atIndex:i];
[array insertObject:tempArray atIndex:[array count]-1];
}
}