fix: Use int instead of float for the example code of log time complexity (#1164)

* Use int instead of float for the example code of log time complexity

* Bug fixes

* Bug fixes
This commit is contained in:
Yudong Jin
2024-03-23 02:17:48 +08:00
committed by GitHub
parent fc8473ccfe
commit 3ea91bda99
12 changed files with 69 additions and 69 deletions

View File

@ -10,7 +10,7 @@ public class time_complexity {
void Algorithm(int n) {
int a = 1; // +0技巧 1
a += n; // +0技巧 1
// +n技巧 2
// +n技巧 2
for (int i = 0; i < 5 * n + 1; i++) {
Console.WriteLine(0);
}
@ -118,7 +118,7 @@ public class time_complexity {
}
/* 对数阶(循环实现) */
int Logarithmic(float n) {
int Logarithmic(int n) {
int count = 0;
while (n > 1) {
n /= 2;
@ -128,13 +128,13 @@ public class time_complexity {
}
/* 对数阶(递归实现) */
int LogRecur(float n) {
int LogRecur(int n) {
if (n <= 1) return 0;
return LogRecur(n / 2) + 1;
}
/* 线性对数阶 */
int LinearLogRecur(float n) {
int LinearLogRecur(int n) {
if (n <= 1) return 1;
int count = LinearLogRecur(n / 2) + LinearLogRecur(n / 2);
for (int i = 0; i < n; i++) {
@ -181,12 +181,12 @@ public class time_complexity {
count = ExpRecur(n);
Console.WriteLine("指数阶(递归实现)的操作数量 = " + count);
count = Logarithmic((float)n);
count = Logarithmic(n);
Console.WriteLine("对数阶(循环实现)的操作数量 = " + count);
count = LogRecur((float)n);
count = LogRecur(n);
Console.WriteLine("对数阶(递归实现)的操作数量 = " + count);
count = LinearLogRecur((float)n);
count = LinearLogRecur(n);
Console.WriteLine("线性对数阶(递归实现)的操作数量 = " + count);
count = FactorialRecur(n);