mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-25 13:46:30 +08:00
fix bug
This commit is contained in:
parent
2572b83540
commit
a667e71b20
3 changed files with 15 additions and 11 deletions
|
@ -56,6 +56,7 @@ int bubbleSort(int *nums, int n) {
|
|||
for (int i = n - 1; i > 0; i--) {
|
||||
// 内循环:冒泡操作
|
||||
for (int j = 0; j < i; j++) {
|
||||
if (nums[j] > nums[j + 1]) {
|
||||
// 交换 nums[j] 与 nums[j + 1]
|
||||
int tmp = nums[j];
|
||||
nums[j] = nums[j + 1];
|
||||
|
@ -63,6 +64,7 @@ int bubbleSort(int *nums, int n) {
|
|||
count += 3; // 元素交换包含 3 个单元操作
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
const std = @import("std");
|
||||
|
||||
// Zig Version: 0.10.0
|
||||
// Zig Codes Build Command: zig build
|
||||
// Build Command: zig build
|
||||
pub fn build(b: *std.build.Builder) void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const mode = b.standardReleaseOptions();
|
||||
|
|
|
@ -59,6 +59,7 @@ fn bubbleSort(nums: []i32) i32 {
|
|||
var j: usize = 0;
|
||||
// 内循环:冒泡操作
|
||||
while (j < i) : (j += 1) {
|
||||
if (nums[j] > nums[j + 1]) {
|
||||
// 交换 nums[j] 与 nums[j + 1]
|
||||
var tmp = nums[j];
|
||||
nums[j] = nums[j + 1];
|
||||
|
@ -66,6 +67,7 @@ fn bubbleSort(nums: []i32) i32 {
|
|||
count += 3; // 元素交换包含 3 个单元操作
|
||||
}
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue