• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Sorting Array Problems
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Sorting Array Problems
      • From: Fritz Anderson <email@hidden>
    • Re: Sorting Array Problems
      • From: Andreas Mayer <email@hidden>
  • Prev by Date: Re: Catching system signals and exception handling
  • Next by Date: NSURLConnection dependency on RunLoop (Sanity check)
  • Previous by thread: Re: NSTableView: option-drag with only one row?
  • Next by thread: Re: Sorting Array Problems
  • Index(es):
    • Date
    • Thread