Sorting Array Problems
Sorting Array Problems
- Subject: Sorting Array Problems
- From: Kodex <email@hidden>
- Date: Thu, 21 Jul 2005 12:16:20 -0700 (PDT)
Ok so I am sorting an array based on its characters,
It sorts ok but every now and then it will overwrite
data or miss a sort. On occassion with certain data it
wont sort correctly at all. Here is my code.
- (IBAction)sortAlpha:(id)sender
{
int x;
int y;
for (x = 0; x < [studentNameA count]; x++)
{
for (y = 0; y < [studentNameA count]; y++)
{
NSString *string1 = [studentNameA objectAtIndex:
x];
NSString *string2 = [studentNameA objectAtIndex:
y];
BOOL ascending = [string1 compare:string2] ==
NSOrderedAscending;
if(ascending)
{
NSLog(@"%@(%i) comes before %@(%i)", string1, x,
string2, y);
[studentNameA insertObject:[studentNameA
objectAtIndex: x] atIndex: y];
[studentNameA removeObjectAtIndex: x+1];
}
}
}
[table reloadData];
}
Anyone know what im doing wrong cause i cant seem to
find the problem here. Thanks!
____________________________________________________
Start your day with Yahoo! - make it your home page
http://www.yahoo.com/r/hs
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden