feat: modify some Dart codes and add Dart code blocks to the docs (#543)

This commit is contained in:
liuyuxin
2023-06-02 14:56:29 +08:00
committed by GitHub
parent 53e18bc6d6
commit 281c0c618a
25 changed files with 339 additions and 54 deletions

View File

@@ -89,7 +89,7 @@ TreeNode? buildTree(int n) {
}
/* Driver Code */
int main() {
void main() {
int n = 5;
// 常数阶
constant(n);
@@ -102,5 +102,4 @@ int main() {
// 指数阶
TreeNode? root = buildTree(n);
printTree(root);
return 0;
}

View File

@@ -50,7 +50,7 @@ int bubbleSort(List<int> nums) {
int count = 0; // 计数器
// 外循环:未排序区间为 [0, i]
for (var i = nums.length - 1; i > 0; i--) {
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
for (var j = 0; j < i; j++) {
if (nums[j] > nums[j + 1]) {
// 交换 nums[j] 与 nums[j + 1]
@@ -122,7 +122,7 @@ int factorialRecur(int n) {
}
/* Driver Code */
int main() {
void main() {
// 可以修改 n 运行,体会一下各种复杂度的操作数量变化趋势
int n = 8;
print('输入数据大小 n = $n');
@@ -160,5 +160,4 @@ int main() {
count = factorialRecur(n);
print('阶乘阶(递归实现)的计算操作数量 = $count');
return 0;
}

View File

@@ -29,7 +29,7 @@ int findOne(List<int> nums) {
}
/* Driver Code */
int main() {
void main() {
for (var i = 0; i < 10; i++) {
int n = 100;
final nums = randomNumbers(n);
@@ -37,6 +37,4 @@ int main() {
print('\n数组 [ 1, 2, ..., n ] 被打乱后 = $nums');
print('数字 1 的索引为 + $index');
}
return 0;
}