mirror of
https://github.com/krahets/hello-algo.git
synced 2025-07-10 17:00:45 +08:00
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:
@ -87,7 +87,7 @@ public class time_complexity {
|
||||
}
|
||||
|
||||
/* 对数阶(循环实现) */
|
||||
static int logarithmic(float n) {
|
||||
static int logarithmic(int n) {
|
||||
int count = 0;
|
||||
while (n > 1) {
|
||||
n = n / 2;
|
||||
@ -97,14 +97,14 @@ public class time_complexity {
|
||||
}
|
||||
|
||||
/* 对数阶(递归实现) */
|
||||
static int logRecur(float n) {
|
||||
static int logRecur(int n) {
|
||||
if (n <= 1)
|
||||
return 0;
|
||||
return logRecur(n / 2) + 1;
|
||||
}
|
||||
|
||||
/* 线性对数阶 */
|
||||
static int linearLogRecur(float n) {
|
||||
static int linearLogRecur(int n) {
|
||||
if (n <= 1)
|
||||
return 1;
|
||||
int count = linearLogRecur(n / 2) + linearLogRecur(n / 2);
|
||||
@ -153,12 +153,12 @@ public class time_complexity {
|
||||
count = expRecur(n);
|
||||
System.out.println("指数阶(递归实现)的操作数量 = " + count);
|
||||
|
||||
count = logarithmic((float) n);
|
||||
count = logarithmic(n);
|
||||
System.out.println("对数阶(循环实现)的操作数量 = " + count);
|
||||
count = logRecur((float) n);
|
||||
count = logRecur(n);
|
||||
System.out.println("对数阶(递归实现)的操作数量 = " + count);
|
||||
|
||||
count = linearLogRecur((float) n);
|
||||
count = linearLogRecur(n);
|
||||
System.out.println("线性对数阶(递归实现)的操作数量 = " + count);
|
||||
|
||||
count = factorialRecur(n);
|
||||
|
Reference in New Issue
Block a user