mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-26 23:16:28 +08:00
Merge pull request #233 from mellowrsa/patch-1
Update time_complexity.md
This commit is contained in:
commit
cbede422e7
1 changed files with 8 additions and 5 deletions
|
@ -1434,11 +1434,14 @@ $$
|
|||
for (int i = n - 1; i > 0; i--) {
|
||||
// 内循环:冒泡操作
|
||||
for (int j = 0; j < i; j++) {
|
||||
// 交换 nums[j] 与 nums[j + 1]
|
||||
int tmp = nums[j];
|
||||
nums[j] = nums[j + 1];
|
||||
nums[j + 1] = tmp;
|
||||
count += 3; // 元素交换包含 3 个单元操作
|
||||
if (nums[j] > nums [j + 1])
|
||||
{
|
||||
// 交换 nums[j] 与 nums[j + 1]
|
||||
int tmp = nums[j];
|
||||
nums[j] = nums[j + 1];
|
||||
nums[j + 1] = tmp;
|
||||
count += 3; // 元素交换包含 3 个单元操作
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue