nike_golf
asked on
Easiest way to replace item in array...
Is there a fast and efficient way to replace an item in a one dimensional array? or do I need to loop through the items and just replace the item that way?
NG,
NG,
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If you are looking for a fast way to determine the INDEX of an item in an array...then No. You have to loop over it to find the right spot that you want to overwrite.
If you need a fast way to do LOOKUPS then use a Collection instead of an Array.
If you need a fast way to do LOOKUPS then use a Collection instead of an Array.
Sorry, was jim horns answer what you were looking for?
If the array is sorted, then a binary tree search is a good way of quickly finding an item
To remove an item is harder
To swap an Item with another part of the array requires a temporary variable of the same type
e.g.
tmpString = aitem(2)
aitem(2) = aitem(4)
aitem(4) = tmpString
Or are none of these the type of thing you are asking about?
If the array is sorted, then a binary tree search is a good way of quickly finding an item
To remove an item is harder
To swap an Item with another part of the array requires a temporary variable of the same type
e.g.
tmpString = aitem(2)
aitem(2) = aitem(4)
aitem(4) = tmpString
Or are none of these the type of thing you are asking about?
Or if you want to replace all items of a certain value...
That either requires a loop (easy & fast on small arrays)
or a binary search on a sorted array, followed by a loop (harder but very fast for large arrays)
That either requires a loop (easy & fast on small arrays)
or a binary search on a sorted array, followed by a loop (harder but very fast for large arrays)
ASKER
Senial moment on my behalf... thanks guy's..
ASKER