1
0
Fork 0
Browse Source

vault backup: 2022-05-11 11:47:17

master
YuJian 3 years ago
parent
commit
5af0fa433c
  1. 58
      数据结构与算法之美/数据结构 - 队列.md

58
数据结构与算法之美/数据结构 - 队列.md

@ -2,36 +2,32 @@
```javascript ```javascript
class StackQueue { class StackQueue {
private stack1: number[] = []; private stack1: number[] = [];
private stack2: number[] = []; private stack2: number[] = [];
add(value: number) {
this.stack1.push(value); add(value: number) {
} this.stack1.push(value);
popup() { }
if (!this.stack1.length) return;
while (this.stack1.length) { popup() {
const stackValue = this.stack1.pop(); if (!this.stack1.length) return;
this.stack2.push(stackValue!); while (this.stack1.length) {
} const stackValue = this.stack1.pop();
const popValue = this.stack2.pop(); this.stack2.push(stackValue!);
while (this.stack2.length) { }
const stackValue = this.stack2.pop();
this.stack1.push(stackValue!); const popValue = this.stack2.pop();
}
while (this.stack2.length) {
const stackValue = this.stack2.pop();
this.stack1.push(stackValue!);
return popValue; }
} return popValue;
}
get length() {
get length() { return this.stack1.length;
}
return this.stack1.length;
}
} }
``` ```
Loading…
Cancel
Save