Write a class that provides the following three methods: 1. Iteratively reverse
ID: 3828199 • Letter: W
Question
Write a class that provides the following three methods: 1. Iteratively reverse a list public static LList iterativeReverseList(LList list) that accepts a reference to a LList and returns a reference to another LList that contains the data of the original list in reverse order. Your method should be implemented using iteration. 2. Recursively Reverse a list public static LList recursiveReverseList(LList list) that accepts a reference to a LList and returns a reference to another LList that contains the data of the original list in reverse order. Your method should be implemented using recursion. 3. Sort Using ArrayList public static ArrayList insertSort(ArrayList list) that accepts a reference to an ArrayLIst and returns another ArrayList that contains the data of the original list in ascending order. You can implement your method as insertion sort or selection sort. You cannot use the Java sort methods. Write a test clExplanation / Answer
public List getPreOrderList() { //TO DO: //this function should return a list of the nodes in pre-order (value, left, right). //It must be implemented recursively!!! //THE PROBLEM: //If i create an ArrayList inside the function, the //recursion will generate each time a new ArrayList. //At the end i get as result an ArrayList with only one node. ArrayList list = new ArrayList(); if (this.value == null) { return null; } //If I just print out the nodes, the pre-order algorithm is OK, //but i need to return all nodes into an ArrayList. System.out.print(value + ", "); list.add(value); if (left != null) { left.getPreOrderList(); } if (right != null) { right.getPreOrderList(); } return list; }Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.