mirror of
https://github.com/krahets/hello-algo.git
synced 2024-12-28 05:36:29 +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,12 +1434,15 @@ $$
|
||||||
for (int i = n - 1; i > 0; i--) {
|
for (int i = n - 1; i > 0; i--) {
|
||||||
// 内循环:冒泡操作
|
// 内循环:冒泡操作
|
||||||
for (int j = 0; j < i; j++) {
|
for (int j = 0; j < i; j++) {
|
||||||
|
if (nums[j] > nums [j + 1])
|
||||||
|
{
|
||||||
// 交换 nums[j] 与 nums[j + 1]
|
// 交换 nums[j] 与 nums[j + 1]
|
||||||
int tmp = nums[j];
|
int tmp = nums[j];
|
||||||
nums[j] = nums[j + 1];
|
nums[j] = nums[j + 1];
|
||||||
nums[j + 1] = tmp;
|
nums[j + 1] = tmp;
|
||||||
count += 3; // 元素交换包含 3 个单元操作
|
count += 3; // 元素交换包含 3 个单元操作
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
|
|
Loading…
Reference in a new issue