为什么Cocoa中没有队列? [英] Why is there no queue in Cocoa?

查看:169
本文介绍了为什么Cocoa中没有队列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近发现,Cocoa没有内置队列(在这种情况下,Touch)。为什么不?队列是计算机编程中最基本的数据结构之一。

I recently found out that there is no queue built into Cocoa (Touch, in this case). Why not? A queue is one of the most fundamental data structures in computer programming.

我看到一些人建议使用 NSMutableArray ,但这对于POP /因为它需要删除索引0处的对象。这将向下移动所有元素(朝向现在的空条目),因此对于每个删除操作取O(n)时间。

I've seen some people suggesting the use of NSMutableArray, but this is extremely inefficient for pops/dequeues, because it requires removing the object at index 0. That will shift all of the elements down (towards the now empty entry), thus taking O(n) time for each remove operation. Am I missing something or was there just no reason that queues were not added to Cocoa?

推荐答案


我看到一些人建议使用 NSMutableArray ,但是这对于POP / DEQUE是非常低效的,因为它需要删除索引为0的对象。这将移动所有元素向下(朝向现在的空条目),因此对于每个删除操作花费O(n)时间。

I've seen some people suggesting the use of NSMutableArray, but this is extremely inefficient for pops/dequeues, because it requires removing the object at index 0. That will shift all of the elements down (towards the now empty entry), thus taking O(n) time for each remove operation.

这是不正确的。 NSMutableArray 非常有效地处理头插入,可用于多种不同的数据结构,包括队列和堆栈。

This is incorrect. NSMutableArray handles head insertion very efficiently and can be used for a number of different data structures, including queues and stacks.

这篇关于为什么Cocoa中没有队列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆