From 03e5807f94f26423a85e3335d8da592e1b2f01b2 Mon Sep 17 00:00:00 2001 From: S-N-O-R-L-A-X Date: Fri, 9 Dec 2022 00:03:04 +0800 Subject: [PATCH] feat: complement doc --- docs/chapter_stack_and_queue/stack.md | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/docs/chapter_stack_and_queue/stack.md b/docs/chapter_stack_and_queue/stack.md index eed7033..9a7e416 100644 --- a/docs/chapter_stack_and_queue/stack.md +++ b/docs/chapter_stack_and_queue/stack.md @@ -403,7 +403,46 @@ comments: true === "TypeScript" ```typescript title="linkedlist_stack.ts" + class ArrayStack { + private stack: number[]; + constructor() { + this.stack = []; + } + /* 获取栈的长度 */ + get size(): number { + return this.stack.length; + } + /* 判断栈是否为空 */ + empty(): boolean { + return this.stack.length === 0; + } + + /* 入栈 */ + push(num: number): void { + this.stack.push(num); + } + + /* 出栈 */ + pop(): number | undefined { + return this.stack.pop(); + } + + /* 访问栈顶元素 */ + top(): number | undefined { + return this.stack[this.stack.length - 1]; + } + + /* 访问索引 index 处元素 */ + get(index: number): number | undefined { + return this.stack[index]; + } + + /* 返回 Array */ + toArray() { + return this.stack; + } + }; ``` === "C"