队列:入队 vs 出队(填写表格,是否需要移位?)

huangapple go评论74阅读模式
英文:

Queue: Enqueue vs Dequeue (Fill out table, Shift needed?)

问题

我正在填写这个表格,想知道我是否做对了:

队列:入队 vs 出队(填写表格,是否需要移位?)

我们是这样学习的:
dequeue(Q) -> 返回最前(右侧)的元素
enqueue(Q,k) -> 将 k 插入为新的最后(左侧)的元素

我有点不确定,因为当我想要 enqueue 一个新项时(所有其他项向前移动一个位置),这样做是否正确?

谢谢您的帮助!

英文:

I'm filling out this table and wondering if I did it right:

队列:入队 vs 出队(填写表格,是否需要移位?)

We learned it like this:
dequeue(Q) -> returns most front (right-hand) element
enqueue(Q,k) -> inserts k as new most rear (left-hand) element

I'm kinda unsure because I have to make a shift, when I want to enqueue a new item (all other items shift by one to the front), is that correct?

Thanks for your help!

答案1

得分: 1

这个图表对于队列数据结构的一个实现是正确的。

如果方框行表示固定大小的数组,这并不是一个非常高效的实现,因为正如你所观察到的,涉及到元素的移动。一种称为循环队列的不同实现消除了移动元素的需求。

英文:

This diagram is correct for one implementation of the queue data structure.

If the row of boxes represents a fixed size array, it's not a very efficient implementation because of the shifting as you've observed. A different implementation called circular queue removes the need to shift items.

huangapple
  • 本文由 发表于 2020年7月27日 18:09:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/63113107.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定