mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-10 14:36:06 +00:00
zig : upgrade codes && rust : add codes for chapter_searching and chapter_dynamic_programming. (#591)
* zig : update zig codes * rust : add codes for linear_search and hashing_search * rust : add codes for linear_search and hashing_search * rust : add codes for chapter_dynamic_programming
This commit is contained in:
@@ -54,7 +54,7 @@ fn quadratic(n: i32) i32 {
|
||||
fn bubbleSort(nums: []i32) i32 {
|
||||
var count: i32 = 0; // 计数器
|
||||
// 外循环:未排序区间为 [0, i]
|
||||
var i: i32 = @intCast(i32, nums.len ) - 1;
|
||||
var i: i32 = @as(i32, @intCast(nums.len)) - 1;
|
||||
while (i > 0) : (i -= 1) {
|
||||
var j: usize = 0;
|
||||
// 内循环:将未排序区间 [0, i] 中的最大元素交换至该区间的最右端
|
||||
@@ -154,7 +154,7 @@ pub fn main() !void {
|
||||
count = quadratic(n);
|
||||
std.debug.print("平方阶的计算操作数量 = {}\n", .{count});
|
||||
for (&nums, 0..) |*num, i| {
|
||||
num.* = n - @intCast(i32, i); // [n,n-1,...,2,1]
|
||||
num.* = n - @as(i32, @intCast(i)); // [n,n-1,...,2,1]
|
||||
}
|
||||
count = bubbleSort(&nums);
|
||||
std.debug.print("平方阶(冒泡排序)的计算操作数量 = {}\n", .{count});
|
||||
|
||||
Reference in New Issue
Block a user