Re: Dificult question continue
Re: Dificult question continue
- Subject: Re: Dificult question continue
- From: Scott Anguish <email@hidden>
- Date: Sat, 20 Jul 2002 21:28:48 -0400
this is pretty basic stuff, and non cocoa oriented really.
If you've got alphabetical order (which you say you do) then you want to
implement a binary search..
look at the first item, if it's greater than the value you're searching
for, you're done and it isn't there.
if it is less than the target item, then go to the element half the
distance to the end of the array.. check that one... if it's greater
than the target, go the one halfway between the first element and the
current element... if it is less than the target, then test the element
half way between the current item and the end of the array.. repeat
until you find the element, or run out of remaining 'halves' to search.
On Saturday, July 20, 2002, at 08:47 PM, Aidas wrote:
I've thinked how to speed up search a little bit. Here is code that I
made
but it's not speeded up:
int i;
int rodyti_pirma;
NSString* laikinas_zodis;
NSString* p_zodis;
BOOL ar_rado;
id theRecord;
int r_numeris;
rodyti_pirma=0;
r_numeris=[sarasas numberOfRows];
for ( i = 0; i <= r_numeris-1; i++ )
{
p_zodis=[komentarai stringValue];
theRecord = [records objectAtIndex:i];
laikinas_zodis=[theRecord objectForKey:@"zodis"];
ar_rado=[laikinas_zodis hasPrefix:p_zodis];
if (ar_rado==YES)
{
if (rodyti_pirma==0)
{
[sarasas selectRow:i byExtendingSelection:NO];
rodyti_pirma=1;
}
}
It searches NSMutableArray. When it founds item that it needs it
continous
it search. I want it to stop it when needed item is found. Is it
possible to
do it using "for ( I=0 balh blah blah)"? Or maybe I should use something
else? I don't know how to use while or loop functions.
Thank you and sorry for bombing this mailling list. :)
Aidas
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.