|
|
@ -4,34 +4,30 @@ |
|
|
|
class StackQueue { |
|
|
|
class StackQueue { |
|
|
|
private stack1: number[] = []; |
|
|
|
private stack1: number[] = []; |
|
|
|
private stack2: number[] = []; |
|
|
|
private stack2: number[] = []; |
|
|
|
|
|
|
|
|
|
|
|
add(value: number) { |
|
|
|
add(value: number) { |
|
|
|
this.stack1.push(value); |
|
|
|
this.stack1.push(value); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
popup() { |
|
|
|
popup() { |
|
|
|
if (!this.stack1.length) return; |
|
|
|
if (!this.stack1.length) return; |
|
|
|
while (this.stack1.length) { |
|
|
|
while (this.stack1.length) { |
|
|
|
const stackValue = this.stack1.pop(); |
|
|
|
const stackValue = this.stack1.pop(); |
|
|
|
this.stack2.push(stackValue!); |
|
|
|
this.stack2.push(stackValue!); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const popValue = this.stack2.pop(); |
|
|
|
const popValue = this.stack2.pop(); |
|
|
|
|
|
|
|
|
|
|
|
while (this.stack2.length) { |
|
|
|
while (this.stack2.length) { |
|
|
|
const stackValue = this.stack2.pop(); |
|
|
|
const stackValue = this.stack2.pop(); |
|
|
|
this.stack1.push(stackValue!); |
|
|
|
this.stack1.push(stackValue!); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return popValue; |
|
|
|
return popValue; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get length() { |
|
|
|
get length() { |
|
|
|
|
|
|
|
|
|
|
|
return this.stack1.length; |
|
|
|
return this.stack1.length; |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
``` |
|
|
|
``` |