From 5af0fa433c89ae600896aaab309f278b3c742c02 Mon Sep 17 00:00:00 2001 From: YuJian Date: Wed, 11 May 2022 11:47:17 +0800 Subject: [PATCH] vault backup: 2022-05-11 11:47:17 --- .../数据结构 - 队列.md | 58 +++++++++---------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/数据结构与算法之美/数据结构 - 队列.md b/数据结构与算法之美/数据结构 - 队列.md index 965b42b..3d303f0 100644 --- a/数据结构与算法之美/数据结构 - 队列.md +++ b/数据结构与算法之美/数据结构 - 队列.md @@ -2,36 +2,32 @@ ```javascript class StackQueue { - private stack1: number[] = []; - private stack2: number[] = []; - add(value: number) { - this.stack1.push(value); - } - popup() { - if (!this.stack1.length) return; - while (this.stack1.length) { - const stackValue = this.stack1.pop(); - this.stack2.push(stackValue!); - } - const popValue = this.stack2.pop(); - while (this.stack2.length) { - const stackValue = this.stack2.pop(); - this.stack1.push(stackValue!); - } - - - - return popValue; - - } - - - - get length() { - - return this.stack1.length; - - } - + private stack1: number[] = []; + private stack2: number[] = []; + + add(value: number) { + this.stack1.push(value); + } + + popup() { + if (!this.stack1.length) return; + while (this.stack1.length) { + const stackValue = this.stack1.pop(); + this.stack2.push(stackValue!); + } + + const popValue = this.stack2.pop(); + + while (this.stack2.length) { + const stackValue = this.stack2.pop(); + this.stack1.push(stackValue!); + } + + return popValue; + } + + get length() { + return this.stack1.length; + } } ``` \ No newline at end of file