JavaScript有类似堆栈(stack)和队列(queue)的对象/容器吗?

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

Does javascript have objects/containers like stack and queues?

问题

学习详细了解数据结构。在网上查看了一些 JavaScript 教程,它们似乎将数组用于所有操作。

例如这样:

  1. class Stack {
  2. // 用数组来实现栈
  3. constructor()
  4. {
  5. this.items = [];
  6. }
  7. // 需要实现的方法
  8. // push(item)
  9. // pop()
  10. // peek()
  11. // isEmpty()
  12. // printStack()
  13. }
英文:

Learning about data structures in details. Checked few js tutorials online and they seemed to use array for everything.

Like this:

  1. class Stack {
  2. // Array is used to implement stack
  3. constructor()
  4. {
  5. this.items = [];
  6. }
  7. // Functions to be implemented
  8. // push(item)
  9. // pop()
  10. // peek()
  11. // isEmpty()
  12. // printStack()
  13. }

答案1

得分: 1

以下是翻译好的内容:

实际上,对于类似堆栈和队列的现有对象容器并不存在,但有一些有效实现它们的技巧。

参考以下链接:
https://chevtek.io/9-javascript-tips-you-may-not-know/
https://yuiazu.net/2019/02/19/stack-and-queue-in-javascript/

希望这对你有帮助 JavaScript有类似堆栈(stack)和队列(queue)的对象/容器吗?

英文:

Actually, there is no existing object containers for the likes of stack and queue but there are a handful of techniques on how you efficiently implement them.

refer to these links:
https://chevtek.io/9-javascript-tips-you-may-not-know/
https://yuiazu.net/2019/02/19/stack-and-queue-in-javascript/

hope this helps JavaScript有类似堆栈(stack)和队列(queue)的对象/容器吗?

huangapple
  • 本文由 发表于 2020年1月3日 20:10:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/59578415.html
匿名

发表评论

匿名网友

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

确定