EvgenyKarkan / EKAlgorithms

EKAlgorithms contains some well known CS algorithms & data structures.
MIT License
2.42k stars 362 forks source link

Is more efficient implementation of reversedArrayWithArray: possible? #35

Closed stanislaw closed 10 years ago

stanislaw commented 10 years ago

Following my previous issue #34:

I think that your original implementation of reversedArrayWithArray can be improved by using the technique similar to what is used in #30 and #31:

Only first n/2 elements should be traversed exchanging i and count-i on each step - the middle element (if it exists - stays one the same position - hm, nice!).

Let me know, what do you think.

EvgenyKarkan commented 10 years ago

Where do you find this API ? ;)

I tried to find this "reversedArrayWithArray" API - but I see it named as "- (NSArray *)reversedArray" now. This API uses native Foundation trick.

If I am not mistaken - in my original implementation I use additional mutable array and add to it objects from the end of given array, I can not remember quite well ;) LOL

stanislaw commented 10 years ago

Yes, sorry, now it IS reversedArray - I've just used the old name.

stanislaw commented 10 years ago

I will do it now. And will show you the concept of CocoaImplementation_.

stanislaw commented 10 years ago

Thanks! Closing this ;)