Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need help with code! Factorial.java ---------------- public class Factorial { public static int factorialRecursive(int n) { if (n == 1 || n == 0) {

Need help with code! Factorial.java ---------------- public class Factorial { public static int factorialRecursive(int n) { if (n == 1 || n == 0) { return 1; } return n * factorialRecursive(n - 1); } public static int factorialTailRecursive(int n) { return factorialTailRecursive(n, 1); } // TODO: Rewrite factorialRecursive as a tail-call recursive function. To review, that means // the return statement for the recursive case should contain only a function and no // other operations. The accumulator argument for the function is already set up for you. public static int factorialTailRecursive(int n, int accum) { return 0; } }

--------------------

LinkedList.java

---------------------

public class LinkedList { static class Node { int data; Node next; } Node node; private int size() { int i = 0; Node n = this.node; while (n != null) { i += 1; n = n.next; } return i; } public int[] toArray() { int[] array = new int[this.size()]; int i = 0; Node n = this.node; while (n != null) { array[i] = n.data; i += 1; n = n.next; } return array; } static public LinkedList fromArray(int[] array) { Node n = null; for (int i = array.length - 1; i >= 0; i--) { Node newNode = new Node(); newNode.data = array[i]; newNode.next = n; n = newNode; } LinkedList list = new LinkedList(); list.node = n; return list; } // TODO: Write a recursive function to combine two sorted linked lists into a new // sorted linked list. This is just like the combine function we went over in // class for the merge sort example, except it operates over linked lists instead // of arrays. private static Node combineRecursive(Node first, Node second) { return null; } public LinkedList combineSorted(LinkedList other) { LinkedList ret = new LinkedList(); ret.node = combineRecursive(this.node, other.node); return ret; } } 

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

Step: 3

blur-text-image

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

Question

KEY QUESTION Refer to Figure 3.6, page

Answered: 1 week ago

Question

What are Decision Trees?

Answered: 1 week ago

Question

What is meant by the Term Glass Ceiling?

Answered: 1 week ago