![]() |
Java
1.0
|
Class for generating the Fibonacci sequence. More...
Public Member Functions | |
Fibonacci () | |
Fibonacci (int n) | |
Constructs a Fibonacci sequence from 0 to n-1. More... | |
void | fibo (int n) |
Prints the Fibonacci sequence. More... | |
long | fiboDumb (int n) |
This is a naive recursive version. More... | |
long | fib (int n) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls. More... | |
long | Fibo (int n) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls. More... | |
String | toString () |
Used to print a Fibonacci object. More... | |
Static Public Member Functions | |
static void | main (String[] args) |
Main function for testing. More... | |
Private Member Functions | |
long | fib (int n, long s1, long s2) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls. More... | |
Private Attributes | |
long | ncalls = 0 |
hold the number of recursive calls More... | |
long[] | fibs = null |
hold the Fibonacci sequence More... | |
int | nf = 0 |
hold the number of terms to be generated More... | |
Class for generating the Fibonacci sequence.
The Fibonacci Sequence is the series of numbers: \(0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...\)
where the next number is found by adding up the two numbers before it.
To compile:
Definition at line 16 of file Fibonacci.java.
Fibonacci.Fibonacci | ( | ) |
Definition at line 31 of file Fibonacci.java.
Referenced by main().
Fibonacci.Fibonacci | ( | int | n | ) |
Constructs a Fibonacci sequence from 0 to n-1.
n | index of the last element of the sequence. |
Definition at line 38 of file Fibonacci.java.
References Fibo().
long Fibonacci.fib | ( | int | n | ) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls.
This method just calls the private version of fib.
n | index of a element of the sequence. |
Definition at line 115 of file Fibonacci.java.
|
private |
void Fibonacci.fibo | ( | int | n | ) |
Prints the Fibonacci sequence.
n | index of the last element of the sequence. |
Definition at line 79 of file Fibonacci.java.
Referenced by main().
long Fibonacci.Fibo | ( | int | n | ) |
Generates a Fibonacci number using a recursive algorithm that makes only n recursive calls.
n | index of a element of the sequence. |
Definition at line 144 of file Fibonacci.java.
References fibs, ncalls, and nf.
Referenced by Fibonacci().
long Fibonacci.fiboDumb | ( | int | n | ) |
|
static |
Main function for testing.
args | index of the last Fibobacci number of the sequence. |
Definition at line 47 of file Fibonacci.java.
References fib(), fibo(), fiboDumb(), Fibonacci(), and ncalls.
String Fibonacci.toString | ( | ) |
|
private |
hold the Fibonacci sequence
Definition at line 24 of file Fibonacci.java.
Referenced by Fibo(), and toString().
|
private |
hold the number of recursive calls
Definition at line 20 of file Fibonacci.java.
Referenced by fib(), Fibo(), fiboDumb(), main(), and toString().
|
private |
hold the number of terms to be generated
Definition at line 28 of file Fibonacci.java.
Referenced by Fibo().