upgrade zig codes to 0.11.0-dev.3379+629f0d23b (#563)

* upgrade zig codes to 0.11.0-dev.3379+629f0d23b

* upgrade zig codes to 0.11.0-dev.3379+629f0d23b
This commit is contained in:
sjinzh
2023-06-25 20:59:00 +08:00
committed by GitHub
parent 62e8f0df50
commit 41b7b229a3
22 changed files with 264 additions and 460 deletions

View File

@@ -153,7 +153,7 @@ pub fn main() !void {
count = quadratic(n);
std.debug.print("平方阶的计算操作数量 = {}\n", .{count});
for (nums) |*num, i| {
for (&nums, 0..) |*num, i| {
num.* = n - @intCast(i32, i); // [n,n-1,...,2,1]
}
count = bubbleSort(&nums);
@@ -174,5 +174,7 @@ pub fn main() !void {
count = factorialRecur(n);
std.debug.print("阶乘阶(递归实现)的计算操作数量 = {}\n", .{count});
_ = try std.io.getStdIn().reader().readByte();
}

View File

@@ -9,7 +9,7 @@ const inc = @import("include");
pub fn randomNumbers(comptime n: usize) [n]i32 {
var nums: [n]i32 = undefined;
// 生成数组 nums = { 1, 2, 3, ..., n }
for (nums) |*num, i| {
for (&nums, 0..) |*num, i| {
num.* = @intCast(i32, i) + 1;
}
// 随机打乱数组元素
@@ -20,7 +20,7 @@ pub fn randomNumbers(comptime n: usize) [n]i32 {
// 查找数组 nums 中数字 1 所在索引
pub fn findOne(nums: []i32) i32 {
for (nums) |num, i| {
for (nums, 0..) |num, i| {
// 当元素 1 在数组头部时,达到最佳时间复杂度 O(1)
// 当元素 1 在数组尾部时,达到最差时间复杂度 O(n)
if (num == 1) return @intCast(i32, i);
@@ -39,5 +39,7 @@ pub fn main() !void {
inc.PrintUtil.printArray(i32, &nums);
std.debug.print("数字 1 的索引为 {}\n", .{index});
}
_ = try std.io.getStdIn().reader().readByte();
}