Skip to content

Commit

Permalink
fix: fix names and move content to correct place
Browse files Browse the repository at this point in the history
  • Loading branch information
S-N-O-R-L-A-X committed Dec 9, 2022
1 parent 7ce5ae1 commit 15120d3
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 82 deletions.
2 changes: 1 addition & 1 deletion codes/javascript/chapter_stack_and_queue/array_stack.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* File: array_stack.ts
* File: array_stack.js
* Created Time: 2022-12-09
* Author: S-N-O-R-L-A-X (snorlax.xu@outlook.com)
*/
Expand Down
163 changes: 82 additions & 81 deletions docs/chapter_stack_and_queue/stack.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,92 +397,13 @@ comments: true
=== "JavaScript"

```js title="linkedlist_stack.js"
/* 基于数组实现的栈 */
class ArrayStack {
stack;
constructor() {
this.stack = [];
}
/* 获取栈的长度 */
get size() {
return this.stack.length;
}

/* 判断栈是否为空 */
empty() {
return this.stack.length === 0;
}

/* 入栈 */
push(num) {
this.stack.push(num);
}

/* 出栈 */
pop() {
return this.stack.pop();
}

/* 访问栈顶元素 */
top() {
return this.stack[this.stack.length - 1];
}

/* 访问索引 index 处元素 */
get(index) {
return this.stack[index];
}

/* 返回 Array */
toArray() {
return this.stack;
}
};

```

=== "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"
Expand Down Expand Up @@ -666,13 +587,93 @@ comments: true
=== "JavaScript"

```js title="array_stack.js"
/* 基于数组实现的栈 */
class ArrayStack {
stack;
constructor() {
this.stack = [];
}
/* 获取栈的长度 */
get size() {
return this.stack.length;
}

/* 判断栈是否为空 */
empty() {
return this.stack.length === 0;
}

/* 入栈 */
push(num) {
this.stack.push(num);
}

/* 出栈 */
pop() {
return this.stack.pop();
}

/* 访问栈顶元素 */
top() {
return this.stack[this.stack.length - 1];
}

/* 访问索引 index 处元素 */
get(index) {
return this.stack[index];
}

/* 返回 Array */
toArray() {
return this.stack;
}
};
```

=== "TypeScript"

```typescript title="array_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"
Expand Down

0 comments on commit 15120d3

Please sign in to comment.