fix(home): Viper 排序示例改用引用传参 &list[int]
函数内要修改外部容器必须走引用传参,签名写 &list[int](与 C++ 的 & / Rust 的 &mut 同理);卡片标注同步改为「引用传参 · 原生产物」。
This commit is contained in:
1 parent
b892206b38
commit
95c0565b7a
1 file changed
+4
-3
@@ -516,13 +516,14 @@ const viperFeatures = [
|
||||
|
||||
/** 同一段插入排序的五语言对照
|
||||
* Viper 版只用官方标准库容器的真实用法:list[T](堆容器),
|
||||
* __getitem__ / __setitem__ 支持下标读写、__len__ 协议支持内置 len(),所以无需外传长度 */
|
||||
* __getitem__ / __setitem__ 支持下标读写、__len__ 协议支持内置 len();
|
||||
* & 是引用传参,函数内要改到外部那个容器就必须带(与 C++ 的 & / Rust 的 &mut 同理) */
|
||||
const sortComparison = [
|
||||
{
|
||||
lang: 'Viper',
|
||||
note: '与 Python 同形 · 原生产物',
|
||||
note: '引用传参 · 原生产物',
|
||||
highlight: true,
|
||||
code: `def sort(nums: list[int]):
|
||||
code: `def sort(nums: &list[int]):
|
||||
for i in range(1, len(nums)):
|
||||
key: int = nums[i]
|
||||
j: int = i - 1
|
||||
|
||||
Reference in new issue
Block a user