Skip to content

Commit

Permalink
更新优先队列的封装
Browse files Browse the repository at this point in the history
  • Loading branch information
XPoet committed Jul 25, 2020
1 parent b052392 commit 82c54b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/PriorityQueue/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import PriorityQueue from './priorityQueue';
import { PriorityQueue } from './priorityQueue';

// ----- 优先队列结构测试 -----//
console.log('// ----- 优先队列结构测试 START -----//');
Expand Down
28 changes: 15 additions & 13 deletions src/PriorityQueue/priorityQueue.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
// 优先队列结构的封装
export default class PriorityQueue {
/**
* 优先队列结构的封装
*/

constructor() {

this.items = [];
// 优先队列内部的元素类
class QueueElement {
constructor(element, priority) {
this.element = element;
this.priority = priority;
}
}

// 内部类
this.QueueElement = class {
constructor(element, priority) {
this.element = element;
this.priority = priority;
}
};
// 优先队列类
export class PriorityQueue {

constructor() {
this.items = [];
}

// enqueue() 入队,将元素按优先级加入到队列中
enqueue(element, priority) {
// 根据传入的元素,创建 QueueElement 对象
const queueElement = new this.QueueElement(element, priority);
const queueElement = new QueueElement(element, priority);

// 判断队列是否为空
if (this.isEmpty()) {
Expand Down

0 comments on commit 82c54b5

Please sign in to comment.