Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(Java Linked List) Create the method getInterleavedArithmeticFibonacciSequence in class ListUtilitires. Refer to the test cases and Node Class for more info: public class Node {

(Java Linked List) Create the method getInterleavedArithmeticFibonacciSequence in class ListUtilitires. Refer to the test cases and Node Class for more info:

public class Node { private E element; private Node next; /* * Constructor */ public Node(E e, Node n) { element = e; next = n; } /* * Accessors */ public E getElement() { return element; } public Node getNext() { return next; } /* * Mutators */ public void setElement(E e) { element = e; } public void setNext(Node n) { next = n; } }

@Test public void test_getInterleavingArithmeticFibonacciSeq_01c() { ListUtilities util = new ListUtilities(); /* * Get a sequence interleaving elements from: * - An arithmetic sequence, starting at 5 with a common difference 3, of size 4. * - A Fibonacci sequence of size 5. * Recall. A Fibonacci sequence is infinite: <1, 1, 2, 3, 5, 8, 13, ...> * (The interleaving starts with one element from the arith. seq., then one element from the Fib. seq., and so on.) */ Node output = util.getInterleavedArithmeticFibonacciSequences(5, 3, 4, 5); assertTrue(5 == output.getElement()); // 1st element from arith. seq. assertTrue(1 == output.getNext().getElement()); // 1st element from Fib. seq. assertTrue(8 == output.getNext().getNext().getElement()); // 2nd element from arith. seq. assertTrue(1 == output.getNext().getNext().getNext().getElement()); // 2nd element from Fib. seq. assertTrue(11 == output.getNext().getNext().getNext().getNext().getElement()); // 3rd element from arith. seq. assertTrue(2 == output.getNext().getNext().getNext().getNext().getNext().getElement()); // 3rd element from Fib. seq. assertTrue(14 == output.getNext().getNext().getNext().getNext().getNext().getNext().getElement()); // 4th element from arith. seq. assertTrue(3 == output.getNext().getNext().getNext().getNext().getNext().getNext().getNext().getElement()); // 4th element from Fib. seq. assertTrue(5 == output.getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getElement()); // 5th element from arith. seq. assertNull(output.getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext().getNext()); } @Test public void test_getInterleavingArithmeticFibonacciSeq_02() { ListUtilities util = new ListUtilities(); /* * Get a sequence interleaving elements from: * - An arithmetic sequence, starting at 5 with a common difference 3, of size 0. * - A Fibonacci sequence of size 0. * In this special case, the resulting interleaving is just empty. */ Node output = util.getInterleavedArithmeticFibonacciSequences(5, 3, 0, 0); assertNull(output); } @Test public void test_getInterleavingArithmeticFibonacciSeq_03() { ListUtilities util = new ListUtilities(); /* * Get a sequence interleaving: * - An arithmetic sequence, starting at 5 with a common difference 3, of size 4. * - A Fibonacci sequence of size 0. * In this special case, the resulting interleaving is just the arithmetic sequence. */ Node output = util.getInterleavedArithmeticFibonacciSequences(5, 3, 4, 0); assertTrue(5 == output.getElement()); assertTrue(8 == output.getNext().getElement()); assertTrue(11 == output.getNext().getNext().getElement()); assertTrue(14 == output.getNext().getNext().getNext().getElement()); assertNull(output.getNext().getNext().getNext().getNext()); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions