开发者

What is the LinkedList equivalent in iOS frameworks?

In java, one can make use of the generic LinkedList to improve the efficiency when object开发者_JAVA百科s are often added to the front of the list. What is its equivalent in the iOS frameworks?


You need to understand that in Foundation classes like NSArray, etc, is not what you learned as an array, etc in your beginning programming class. In particular, it doesn't have the performance characteristics you would normally associate to an array.

On this point, there are many nice blog posts, e.g. one by Ridiculous Fish and another by Cocoa with Love

So, as everybody else said, just use NSMutableArray.


NSMutableArray is closest to this. Despite the name, it's closer to a list than an array. However, "appending to and removing elements from either end take constant time", according to this.

Also, what about this, a third-party implementation: https://github.com/mschettler/NSLinkedList


There is no direct equivalent. Writing a linked list yourself is pretty easy, but I doubt that you will gain a lot of performance compared to NSMutableArray.

There are a couple of different linked list implementations in the open source CHDataStructures.


NSMutableArray is a vector or dynamic array but it is not a linkedlist.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜