mirror of
https://github.com/krahets/hello-algo.git
synced 2026-07-25 12:36:07 +00:00
Many bug fixes and improvements (#1270)
* Add Ruby and Kotlin icons Add the avatar of @curtishd * Update README * Synchronize zh-hant and zh versions. * Translate the pythontutor blocks to traditional Chinese * Fix en/mkdocs.yml * Update the landing page of the en version. * Fix the Dockerfile * Refine the en landingpage * Fix en landing page * Reset the README.md
This commit is contained in:
@@ -9,7 +9,7 @@ package chapter_computational_complexity.time_complexity
|
||||
/* 常數階 */
|
||||
fun constant(n: Int): Int {
|
||||
var count = 0
|
||||
val size = 10_0000
|
||||
val size = 100000
|
||||
for (i in 0..<size)
|
||||
count++
|
||||
return count
|
||||
@@ -48,7 +48,7 @@ fun quadratic(n: Int): Int {
|
||||
|
||||
/* 平方階(泡沫排序) */
|
||||
fun bubbleSort(nums: IntArray): Int {
|
||||
var count = 0
|
||||
var count = 0 // 計數器
|
||||
// 外迴圈:未排序區間為 [0, i]
|
||||
for (i in nums.size - 1 downTo 1) {
|
||||
// 內迴圈:將未排序區間 [0, i] 中的最大元素交換至該區間的最右端
|
||||
@@ -109,7 +109,7 @@ fun linearLogRecur(n: Int): Int {
|
||||
if (n <= 1)
|
||||
return 1
|
||||
var count = linearLogRecur(n / 2) + linearLogRecur(n / 2)
|
||||
for (i in 0..<n.toInt()) {
|
||||
for (i in 0..<n) {
|
||||
count++
|
||||
}
|
||||
return count
|
||||
@@ -133,7 +133,7 @@ fun main() {
|
||||
val n = 8
|
||||
println("輸入資料大小 n = $n")
|
||||
|
||||
var count: Int = constant(n)
|
||||
var count = constant(n)
|
||||
println("常數階的操作數量 = $count")
|
||||
|
||||
count = linear(n)
|
||||
@@ -144,7 +144,8 @@ fun main() {
|
||||
count = quadratic(n)
|
||||
println("平方階的操作數量 = $count")
|
||||
val nums = IntArray(n)
|
||||
for (i in 0..<n) nums[i] = n - i // [n,n-1,...,2,1]
|
||||
for (i in 0..<n)
|
||||
nums[i] = n - i // [n,n-1,...,2,1]
|
||||
count = bubbleSort(nums)
|
||||
println("平方階(泡沫排序)的操作數量 = $count")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user