Many bug fixes and improvements (#1270)

* Add Ruby and Kotlin icons
Add the avatar of @curtishd

* Update README

* Synchronize zh-hant and zh versions.

* Translate the pythontutor blocks to traditional Chinese

* Fix en/mkdocs.yml

* Update the landing page of the en version.

* Fix the Dockerfile

* Refine the en landingpage

* Fix en landing page

* Reset the README.md
This commit is contained in:
Yudong Jin
2024-04-11 20:18:19 +08:00
committed by GitHub
parent 07977184ad
commit b2f0d4603d
192 changed files with 2382 additions and 1196 deletions

View File

@@ -26,25 +26,25 @@
```python title="stack.py"
# 初始化堆疊
# Python 沒有內建的堆疊類別,可以把 list 當作堆疊來使用
# Python 沒有內建的堆疊類別,可以把 list 當作堆疊來使用
stack: list[int] = []
# 元素入堆疊
stack.append(1)
stack.append(3)
stack.append(2)
stack.append(5)
stack.append(4)
# 訪問堆疊頂元素
peek: int = stack[-1]
# 元素出堆疊
pop: int = stack.pop()
# 獲取堆疊的長度
size: int = len(stack)
# 判斷是否為空
is_empty: bool = len(stack) == 0
```
@@ -54,23 +54,23 @@
```cpp title="stack.cpp"
/* 初始化堆疊 */
stack<int> stack;
/* 元素入堆疊 */
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
/* 訪問堆疊頂元素 */
int top = stack.top();
/* 元素出堆疊 */
stack.pop(); // 無返回值
/* 獲取堆疊的長度 */
int size = stack.size();
/* 判斷是否為空 */
bool empty = stack.empty();
```
@@ -106,23 +106,23 @@
```csharp title="stack.cs"
/* 初始化堆疊 */
Stack<int> stack = new();
/* 元素入堆疊 */
stack.Push(1);
stack.Push(3);
stack.Push(2);
stack.Push(5);
stack.Push(4);
/* 訪問堆疊頂元素 */
int peek = stack.Peek();
/* 元素出堆疊 */
int pop = stack.Pop();
/* 獲取堆疊的長度 */
int size = stack.Count;
/* 判斷是否為空 */
bool isEmpty = stack.Count == 0;
```
@@ -133,24 +133,24 @@
/* 初始化堆疊 */
// 在 Go 中,推薦將 Slice 當作堆疊來使用
var stack []int
/* 元素入堆疊 */
stack = append(stack, 1)
stack = append(stack, 3)
stack = append(stack, 2)
stack = append(stack, 5)
stack = append(stack, 4)
/* 訪問堆疊頂元素 */
peek := stack[len(stack)-1]
/* 元素出堆疊 */
pop := stack[len(stack)-1]
stack = stack[:len(stack)-1]
/* 獲取堆疊的長度 */
size := len(stack)
/* 判斷是否為空 */
isEmpty := len(stack) == 0
```
@@ -161,23 +161,23 @@
/* 初始化堆疊 */
// Swift 沒有內建的堆疊類別,可以把 Array 當作堆疊來使用
var stack: [Int] = []
/* 元素入堆疊 */
stack.append(1)
stack.append(3)
stack.append(2)
stack.append(5)
stack.append(4)
/* 訪問堆疊頂元素 */
let peek = stack.last!
/* 元素出堆疊 */
let pop = stack.removeLast()
/* 獲取堆疊的長度 */
let size = stack.count
/* 判斷是否為空 */
let isEmpty = stack.isEmpty
```
@@ -186,25 +186,25 @@
```javascript title="stack.js"
/* 初始化堆疊 */
// JavaScript 沒有內建的堆疊類別,可以把 Array 當作堆疊來使用
// JavaScript 沒有內建的堆疊類別,可以把 Array 當作堆疊來使用
const stack = [];
/* 元素入堆疊 */
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
/* 訪問堆疊頂元素 */
const peek = stack[stack.length-1];
/* 元素出堆疊 */
const pop = stack.pop();
/* 獲取堆疊的長度 */
const size = stack.length;
/* 判斷是否為空 */
const is_empty = stack.length === 0;
```
@@ -213,25 +213,25 @@
```typescript title="stack.ts"
/* 初始化堆疊 */
// TypeScript 沒有內建的堆疊類別,可以把 Array 當作堆疊來使用
// TypeScript 沒有內建的堆疊類別,可以把 Array 當作堆疊來使用
const stack: number[] = [];
/* 元素入堆疊 */
stack.push(1);
stack.push(3);
stack.push(2);
stack.push(5);
stack.push(4);
/* 訪問堆疊頂元素 */
const peek = stack[stack.length - 1];
/* 元素出堆疊 */
const pop = stack.pop();
/* 獲取堆疊的長度 */
const size = stack.length;
/* 判斷是否為空 */
const is_empty = stack.length === 0;
```
@@ -301,23 +301,23 @@
```kotlin title="stack.kt"
/* 初始化堆疊 */
val stack = Stack<Int>()
/* 元素入堆疊 */
stack.push(1)
stack.push(3)
stack.push(2)
stack.push(5)
stack.push(4)
/* 訪問堆疊頂元素 */
val peek = stack.peek()
/* 元素出堆疊 */
val pop = stack.pop()
/* 獲取堆疊的長度 */
val size = stack.size
/* 判斷是否為空 */
val isEmpty = stack.isEmpty()
```
@@ -325,7 +325,28 @@
=== "Ruby"
```ruby title="stack.rb"
# 初始化堆疊
# Ruby 沒有內建的堆疊類別,可以把 Array 當作堆疊來使用
stack = []
# 元素入堆疊
stack << 1
stack << 3
stack << 2
stack << 5
stack << 4
# 訪問堆疊頂元素
peek = stack.last
# 元素出堆疊
pop = stack.pop
# 獲取堆疊的長度
size = stack.length
# 判斷是否為空
is_empty = stack.empty?
```
=== "Zig"
@@ -336,7 +357,7 @@
??? pythontutor "視覺化執行"
https://pythontutor.com/render.html#code=%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E6%A0%88%0A%20%20%20%20%23%20Python%20%E6%B2%A1%E6%9C%89%E5%86%85%E7%BD%AE%E7%9A%84%E6%A0%88%E7%B1%BB%EF%BC%8C%E5%8F%AF%E4%BB%A5%E6%8A%8A%20list%20%E5%BD%93%E4%BD%9C%E6%A0%88%E6%9D%A5%E4%BD%BF%E7%94%A8%0A%20%20%20%20stack%20%3D%20%5B%5D%0A%0A%20%20%20%20%23%20%E5%85%83%E7%B4%A0%E5%85%A5%E6%A0%88%0A%20%20%20%20stack.append%281%29%0A%20%20%20%20stack.append%283%29%0A%20%20%20%20stack.append%282%29%0A%20%20%20%20stack.append%285%29%0A%20%20%20%20stack.append%284%29%0A%20%20%20%20print%28%22%E6%A0%88%20stack%20%3D%22,%20stack%29%0A%0A%20%20%20%20%23%20%E8%AE%BF%E9%97%AE%E6%A0%88%E9%A1%B6%E5%85%83%E7%B4%A0%0A%20%20%20%20peek%20%3D%20stack%5B-1%5D%0A%20%20%20%20print%28%22%E6%A0%88%E9%A1%B6%E5%85%83%E7%B4%A0%20peek%20%3D%22,%20peek%29%0A%0A%20%20%20%20%23%20%E5%85%83%E7%B4%A0%E5%87%BA%E6%A0%88%0A%20%20%20%20pop%20%3D%20stack.pop%28%29%0A%20%20%20%20print%28%22%E5%87%BA%E6%A0%88%E5%85%83%E7%B4%A0%20pop%20%3D%22,%20pop%29%0A%20%20%20%20print%28%22%E5%87%BA%E6%A0%88%E5%90%8E%20stack%20%3D%22,%20stack%29%0A%0A%20%20%20%20%23%20%E8%8E%B7%E5%8F%96%E6%A0%88%E7%9A%84%E9%95%BF%E5%BA%A6%0A%20%20%20%20size%20%3D%20len%28stack%29%0A%20%20%20%20print%28%22%E6%A0%88%E7%9A%84%E9%95%BF%E5%BA%A6%20size%20%3D%22,%20size%29%0A%0A%20%20%20%20%23%20%E5%88%A4%E6%96%AD%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A9%BA%0A%20%20%20%20is_empty%20%3D%20len%28stack%29%20%3D%3D%200%0A%20%20%20%20print%28%22%E6%A0%88%E6%98%AF%E5%90%A6%E4%B8%BA%E7%A9%BA%20%3D%22,%20is_empty%29&cumulative=false&curInstr=2&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false
https://pythontutor.com/render.html#code=%22%22%22Driver%20Code%22%22%22%0Aif%20__name__%20%3D%3D%20%22__main__%22%3A%0A%20%20%20%20%23%20%E5%88%9D%E5%A7%8B%E5%8C%96%E5%A0%86%E7%96%8A%0A%20%20%20%20%23%20Python%20%E6%B2%92%E6%9C%89%E5%85%A7%E5%BB%BA%E7%9A%84%E5%A0%86%E7%96%8A%E9%A1%9E%E5%88%A5%EF%BC%8C%E5%8F%AF%E4%BB%A5%E6%8A%8A%20list%20%E7%95%B6%E4%BD%9C%E5%A0%86%E7%96%8A%E4%BE%86%E4%BD%BF%E7%94%A8%0A%20%20%20%20stack%20%3D%20%5B%5D%0A%0A%20%20%20%20%23%20%E5%85%83%E7%B4%A0%E5%85%A5%E5%A0%86%E7%96%8A%0A%20%20%20%20stack.append%281%29%0A%20%20%20%20stack.append%283%29%0A%20%20%20%20stack.append%282%29%0A%20%20%20%20stack.append%285%29%0A%20%20%20%20stack.append%284%29%0A%20%20%20%20print%28%22%E5%A0%86%E7%96%8A%20stack%20%3D%22%2C%20stack%29%0A%0A%20%20%20%20%23%20%E8%A8%AA%E5%95%8F%E5%A0%86%E7%96%8A%E9%A0%82%E5%85%83%E7%B4%A0%0A%20%20%20%20peek%20%3D%20stack%5B-1%5D%0A%20%20%20%20print%28%22%E5%A0%86%E7%96%8A%E9%A0%82%E5%85%83%E7%B4%A0%20peek%20%3D%22%2C%20peek%29%0A%0A%20%20%20%20%23%20%E5%85%83%E7%B4%A0%E5%87%BA%E5%A0%86%E7%96%8A%0A%20%20%20%20pop%20%3D%20stack.pop%28%29%0A%20%20%20%20print%28%22%E5%87%BA%E5%A0%86%E7%96%8A%E5%85%83%E7%B4%A0%20pop%20%3D%22%2C%20pop%29%0A%20%20%20%20print%28%22%E5%87%BA%E5%A0%86%E7%96%8A%E5%BE%8C%20stack%20%3D%22%2C%20stack%29%0A%0A%20%20%20%20%23%20%E7%8D%B2%E5%8F%96%E5%A0%86%E7%96%8A%E7%9A%84%E9%95%B7%E5%BA%A6%0A%20%20%20%20size%20%3D%20len%28stack%29%0A%20%20%20%20print%28%22%E5%A0%86%E7%96%8A%E7%9A%84%E9%95%B7%E5%BA%A6%20size%20%3D%22%2C%20size%29%0A%0A%20%20%20%20%23%20%E5%88%A4%E6%96%B7%E6%98%AF%E5%90%A6%E7%82%BA%E7%A9%BA%0A%20%20%20%20is_empty%20%3D%20len%28stack%29%20%3D%3D%200%0A%20%20%20%20print%28%22%E5%A0%86%E7%96%8A%E6%98%AF%E5%90%A6%E7%82%BA%E7%A9%BA%20%3D%22%2C%20is_empty%29&cumulative=false&curInstr=2&heapPrimitives=nevernest&mode=display&origin=opt-frontend.js&py=311&rawInputLstJSON=%5B%5D&textReferences=false
## 堆疊的實現