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

@ -86,7 +86,7 @@ int expRecur(int n) {
}
/* 对数阶(循环实现) */
int logarithmic(float n) {
int logarithmic(int n) {
int count = 0;
while (n > 1) {
n = n / 2;
@ -96,14 +96,14 @@ int logarithmic(float n) {
}
/* 对数阶(递归实现) */
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);
@ -153,12 +153,12 @@ int main() {
count = expRecur(n);
cout << "指数阶(递归实现)的操作数量 = " << count << endl;
count = logarithmic((float)n);
count = logarithmic(n);
cout << "对数阶(循环实现)的操作数量 = " << count << endl;
count = logRecur((float)n);
count = logRecur(n);
cout << "对数阶(递归实现)的操作数量 = " << count << endl;
count = linearLogRecur((float)n);
count = linearLogRecur(n);
cout << "线性对数阶(递归实现)的操作数量 = " << count << endl;
count = factorialRecur(n);