Question: The following program is in Java, please solve carefully. The following function is supposed to take a list and return a copy of the list

 The following program is in Java, please solve carefully. The following The following program is in Java, please solve carefully.

The following function is supposed to take a list and return a copy of the list with the order of the elements reversed. However, it doesn't work as intended. Point out the problems, and explain how to fix them. rev public static List reverse(List lst){ List rev; if (1st instanceof ArrayList){ = new ArrayList(); } else { rev = new LinkedList(); } Iterator it = lst.listIterator(1st.size()-1); while (it.hasPrevious()){ rev.add(1, it.previous()); } return rev; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!