System.register(["cc"], function (_export, _context) { "use strict"; var _cclegacy, Queue, Deque, _crd; _export({ default: void 0, Deque: void 0 }); return { setters: [function (_cc) { _cclegacy = _cc.cclegacy; }], execute: function () { _crd = true; _cclegacy._RF.push({}, "16900mmPzlPkZiuO57PxvRs", "Queue", undefined); _export("default", Queue = class Queue { constructor() { this.count = void 0; this.lowestCount = void 0; this.items = void 0; this.count = 0; this.lowestCount = 0; this.items = {}; } /**加入队列*/ enqueue(item) { // 队列的末尾添加元素: 将队列的大小作为key this.items[this.count] = item; this.count++; } /**拿出队首*/ dequeue() { if (this.isEmpty()) { return undefined; } var result = this.items[this.lowestCount]; // 删除队首元素 delete this.items[this.lowestCount]; // 队首元素自增 this.lowestCount++; return result; } /**是否为空队列*/ isEmpty() { return this.count - this.lowestCount === 0; } /**查看下一个出队元素 */ peek() { if (this.isEmpty()) { return undefined; } return this.items[this.lowestCount]; } /**队列个数*/ size() { return this.count - this.lowestCount; } /**清空队列*/ clear() { this.count = 0; this.lowestCount = 0; this.items = {}; } toString() { if (this.isEmpty()) { return ""; } var objString = "" + this.items[this.lowestCount]; for (var i = this.lowestCount + 1; i < this.count; i++) { objString = objString + "," + this.items[i]; } return objString; } }); /** * 双端队列 */ _export("Deque", Deque = class Deque { constructor() { this.items = void 0; this.lowestCount = void 0; this.count = void 0; this.items = {}; this.lowestCount = 0; this.count = 0; } /** * 向队列的尾端添加元素 * @param element * @returns size */ addTail(element) { this.items[this.count++] = element; return this.size(); } /** * 向队列头部添加元素 * @param element * @returns size */ addHead(element) { if (this.count === 0) { this.addTail(element); } else if (this.lowestCount > 0) { this.items[--this.lowestCount] = element; } else { for (var i = this.count; i > this.lowestCount; i--) { this.items[i] = this.items[i - 1]; } this.count++; this.items[0] = element; } return this.size(); } /** * 返回队列尾部的元素 * @returns T */ getTail() { if (this.isEmpty()) return undefined; this.count--; var res = this.items[this.count]; delete this.items[this.count]; return res; } /** * 返回头部元素 * @returns T */ getHead() { if (this.isEmpty()) return undefined; var res = this.items[this.lowestCount]; delete this.items[this.lowestCount]; this.lowestCount++; return res; } /** * 看一下队列首部的元素 * @returns T */ peekHead() { if (this.isEmpty()) return undefined; return this.items[this.lowestCount]; } /** * 看一下队列尾部的元素 * @return T */ peekTail() { if (this.isEmpty()) return undefined; return this.items[this.count - 1]; } /** * 返回元素的个数 * @returns number */ size() { return this.count - this.lowestCount; } /** * 判断队列是否为空 */ isEmpty() { return this.size() === 0; } /** * 清空队列 */ clear() { this.items = {}; this.count = this.lowestCount = 0; } toString() { if (this.isEmpty()) { return ''; } var res = this.items[this.lowestCount].toString(); for (var i = this.lowestCount + 1; i < this.count; i++) { res = res + ", " + this.items[i].toString(); } return res; } }); _cclegacy._RF.pop(); _crd = false; } }; }); //# sourceMappingURL=df48ec67964f126550b0d5d71bec2b4cfc027d50.js.map