Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1-implement zip method in Q1 class to merge two linkedlists into one. * The elements in the result are made by concatenating elements in different

1-implement zip method in Q1 class to merge two linkedlists into one. * The elements in the result are made by concatenating elements in different * linkedlists one after one. The order of the elements matters. * For example, merge(list1, list2) should return [1,5,2,4,3,3,4,2,5,1]. * You can assume that arr1 and arr2 has the same size. * HINT: You should use ListIterator to make it easier.

Integer[] arr1 = {1,2,3,4,5}; Integer[] arr2 = {5,4,3,2,1}; LinkedList list1 = new LinkedList<>(Arrays.asList(arr1)); LinkedList list2 = new LinkedList<>(Arrays.asList(arr2)); System.out.println("Q1 = [15 marks] ================================="); System.out.println(Q1.zip(list1, list2));

2- implement reverse method in Q2 class to reverse a string with stack. * For example, string "wonderful" will return "lufrednow". * NOTE: reverse without using a stack will result in 0 for this question.

String word = "wonderful"; System.out.println("Q2 = [15 marks] ================================="); System.out.println(Q2.reverse(word));

3- create Q3 class to implement comparator for a TreeSet. The purpose of * the comparator is to compare the alphabetic order of integers. With Q3, * the order of Integer elements will be sort according to the order of * digit Unicode. * For example, the value of {11,3,31,2} will return {11,2,3,31} * NOTE: You don't need to compare each digit one by one. Just compare them * as strings.

System.out.println("Q3 = [15 marks] ================================="); Set set = new TreeSet<>(new Q3()); Integer[] arr3 = {11,3,31,2}; set.addAll(Arrays.asList(arr3)); for (Integer element: set) System.out.print(element+"\t"); System.out.println();

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

Modern Database Management

Authors: Jeffrey A. Hoffer Fred R. McFadden

9th Edition

B01JXPZ7AK, 9780805360479

More Books

Students also viewed these Databases questions