We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
概念: 队列和栈十分相似,他们都是线性表,元素都是有序的,不同之处是,队列遵循的是 FIFO(先进先出)的原则。 队列从尾部添加新元素,从顶部移除元素,最新添加的元素排在队列的末尾。
理解: 队列在生活中最常见的例子就是排队了,先进入队列的先接受服务,后进入队列的排在队列后面。
队列的模拟:
class Queue { constructor() { this.item = []; } // 添加一个(或几个)新元素到队列尾部 enqueue(element) { items.push(element); } // 移除队列的第一个元素,并返回被移除的元素 dequeue() { return items.shift(); } // 返回队列第一个元素,但不对队列做修改 front() { return items[0]; } // 判断是否为空队列(没有任何元素) isEmpty() { return items.length === 0; } // 返回队列里的元素个数 size() { return items.length; } // 清空队列 clear() { items = []; } }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
概念:
队列和栈十分相似,他们都是线性表,元素都是有序的,不同之处是,队列遵循的是 FIFO(先进先出)的原则。
队列从尾部添加新元素,从顶部移除元素,最新添加的元素排在队列的末尾。
理解:
队列在生活中最常见的例子就是排队了,先进入队列的先接受服务,后进入队列的排在队列后面。
队列的模拟:
The text was updated successfully, but these errors were encountered: