# 文章標題
這是一個包含表格和程式碼的 Markdown 範例。
| 功能 | 狀態 |
| :--- | :--- |
| 表格 | 正常 |
| 程式碼高亮 | 正常 |
| 語言標籤 | **測試中** |
```javascript
// 檢查右上角是否有標籤
function finalTest() {
const feature = "Language Label";
console.log(`Testing the ${feature}...`);
return true;
}
finalTest();
```
```cpp
#include
#include
#include
#include
struct Person {
std::string name;
int age;
};
int main() {
std::vector people = {
{"Alice", 30},
{"Bob", 25},
{"Charlie", 35}
};
// 使用 lambda 運算式定義比較函式,按年齡升序排序
std::ranges::sort(people, [](const Person& a, const Person& b) {
return a.age < b.age;
});
for (const auto& person : people) {
std::cout << person.name << " (" << person.age << ")" << std::endl;
}
return 0;
}
```
```python
class Person:
def __init__(self, name, age):
self.name = name
self.age = age
people = [
Person("Alice", 30),
Person("Bob", 25),
Person("Charlie", 35)
]
# 使用 lambda 函式作為 key,按年齡升序排序
people.sort(key=lambda person: person.age)
for person in people:
print(f"{person.name} ({person.age})")
```
```go
package main
import (
"fmt"
"slices"
)
type Person struct {
Name string
Age int
}
func main() {
people := []Person{
{"Alice", 30},
{"Bob", 25},
{"Charlie", 35},
}
// 按年齡升序排序
slices.SortFunc(people, func(a, b Person) int {
if a.Age < b.Age {
return -1
}
if a.Age > b.Age {
return 1
}
return 0
})
fmt.Println(people)
}
```
```rust
#[derive(Debug, Eq, Ord, PartialEq, PartialOrd)]
struct Person {
name: String,
age: u32,
}
fn main() {
let mut people = vec![
Person { name: "Alice".to_string(), age: 30 },
Person { name: "Bob".to_string(), age: 25 },
Person { name: "Charlie".to_string(), age: 35 },
];
// 1. 使用 sort_unstable_by_key 按年齡升序排序
people.sort_unstable_by_key(|p| p.age);
println!("{:?}", people);
// 2. 使用 sort_unstable_by 按年齡降序排序
people.sort_unstable_by(|a, b| b.age.cmp(&a.age));
println!("{:?}", people);
}
```
| 語言 | 方法 | 回傳值 |
| --- | --- | --- |
| C++ | 比較函式 | `bool` |
| Python | Key Function | 任何可比較的值 |
| Go | 比較函式 | `-1`, `0`, `1` |
| Rust | Key Function 或比較函式 | 任何可比較的值或 `Ordering` |