The API for the Queue class is given below . a queue can only store non- negativ
ID: 3622335 • Letter: T
Question
The API for the Queue class is given below . a queue can only store non- negative ints.
constructor summary
queue ( )
constructor an empty queue
method summary
int : dequeue ()
remove and retune the first element in the queue. return -1 if the queue is empty
void: enqueue ( int value)
if the given value is positve, add it to the end of the queue
int: getFirst()
return the first element in the queue. return -1 if the queue is empty
The API for the stack class is given below. a stack can only store non-negative ints.
Constructor summary
Stack ()
construct an empty stack
method summary
int: pop()
remove and return the top element in the stack. return -1 if the stack is empty
void: push (int value)
if the given value is positive, add it to the top of the stack
using the above API for Stacks and Queues, write a method to calculate the nth Fibonacci number. this method must not declare and /or use any local and/ or global variables other than one Stack, one Queue, and one loop counters. note: the first and second Fibonacci numbers are 1, and the nth Fibonacci number is the sum of the n-1st and n-2nd Fibonacci numbers. thus, the series is as follows:
1,1,2,3,5,8,13,21,34,55,...
public static int calculateFibonacci (int n)
Explanation / Answer
Dear... Method for calculate the nth Fibonacci number. public int calculateFibonacci (int n) { Stack s= new Stack(); Queue q = new Queue(); if (nRelated Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.