Question: import java.util.*; public class Methods { // Second largest method public static int secondLargest(int[] arr) { int largest = arr[0], secondLargest = arr[1]; if (largest

import java.util.*;

public class Methods {

// Second largest method

public static int secondLargest(int[] arr) { int largest = arr[0], secondLargest = arr[1]; if (largest < secondLargest) { int temp = largest; largest = secondLargest; secondLargest = temp; } for (int i = 2; i < arr.length; i++) { if (arr[i] > largest) { secondLargest = largest; largest = arr[i]; } else if (arr[i] > secondLargest) { secondLargest = arr[i]; } } return secondLargest; }

// A method that prints array elements 10 elements per line. public static void printArray(int[] arr) { for(int i = 1; i <= arr.length; i++) { System.out.print(" " + i); if(i % 10 == 0) System.out.print(" "); } } //A mergesort method that mergesorts array elements in descending order.

public int[] merge_sort(int[] array) { if (array.length <= 1) { return array; } int midPoint = array.length / 2; int[] left = new int[midPoint]; int[] right = new int[array.length - midPoint]; int result[] = new int[array.length]; for (int i = 0; i < midPoint; i++) { left[i] = array[i]; } int x = 0; for (int j = midPoint; j < array.length; j++) { if (x < right.length) { right[x] = array[j]; x++; } } left = merge_sort(left); right = merge_sort(right); result = merge(left, right); return result; }

int[] merge(int[] left, int[] right) { int lengthResult = left.length + right.length; int indexL = 0; int indexR = 0; int resultIndex = 0; int[] result = new int[lengthResult]; while (indexL < left.length || indexR < right.length) { if (indexL < left.length && indexR < right.length) { if (left[indexL] >= right[indexR]) { result[resultIndex] = left[indexL]; indexL++; resultIndex++; } else { result[resultIndex] = right[indexR]; indexR++; resultIndex++; } } else if (indexL < left.length) { result[resultIndex] = left[indexL]; indexL++; resultIndex++; } else if (indexR < right.length) { result[resultIndex] = right[indexR]; indexR++; resultIndex++; } } return result; } // Method for search public static int binarySearch(int arr[], int x) {

int l = 0, r = arr.length - 1;

while (l <= r) {

int m = l + (r - l) / 2;

if (arr[m] == x)

return m;

else if (arr[m] < x)

l = m + 1;

else

r = m - 1;

}

return -1;

} }

i need help with writing driver class for this methods.java

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!