mirror of
https://github.com/krahets/hello-algo.git
synced 2025-11-02 21:24:53 +08:00
Improve the consistency between code and comments in Kotlin (#1268)
* style(kotlin): Make code and comments consistent. * style(kotlin): convert comment location. * style(c): Add missing comment. * style(kotlin): Remove redundant semicolon, parenthesis and brace * style(kotlin): Put constants inside the function. * style(kotlin): fix unnecessary indentation. * style(swift): Add missing comment. * style(kotlin): Add missing comment. * style(kotlin): Remove redundant comment. * style(kotlin): Add missing comment. * Update linked_list.kt * style(csharp,js,ts): Add missing comment. * style(kotlin): Remove empty lines. * Update list.cs * Update list.js * Update list.ts * roll back to commit 1 * style(cs,js,ts): Add missing comment in docfile. * style(kotlin): Use normal element swapping instead of scope functions.
This commit is contained in:
@ -18,7 +18,6 @@ fun constant(n: Int): Int {
|
||||
/* 线性阶 */
|
||||
fun linear(n: Int): Int {
|
||||
var count = 0
|
||||
// 循环次数与数组长度成正比
|
||||
for (i in 0..<n)
|
||||
count++
|
||||
return count
|
||||
@ -55,7 +54,9 @@ fun bubbleSort(nums: IntArray): Int {
|
||||
for (j in 0..<i) {
|
||||
if (nums[j] > nums[j + 1]) {
|
||||
// 交换 nums[j] 与 nums[j + 1]
|
||||
nums[j] = nums[j + 1].also { nums[j + 1] = nums[j] }
|
||||
val temp = nums[j]
|
||||
nums[j] = nums[j + 1]
|
||||
nums[j + 1] = temp
|
||||
count += 3 // 元素交换包含 3 个单元操作
|
||||
}
|
||||
}
|
||||
@ -66,8 +67,8 @@ fun bubbleSort(nums: IntArray): Int {
|
||||
/* 指数阶(循环实现) */
|
||||
fun exponential(n: Int): Int {
|
||||
var count = 0
|
||||
// 细胞每轮一分为二,形成数列 1, 2, 4, 8, ..., 2^(n-1)
|
||||
var base = 1
|
||||
// 细胞每轮一分为二,形成数列 1, 2, 4, 8, ..., 2^(n-1)
|
||||
for (i in 0..<n) {
|
||||
for (j in 0..<base) {
|
||||
count++
|
||||
|
||||
Reference in New Issue
Block a user