Question

In: Computer Science

JAVA please write this method public static void recursiveSelectionSort(int[] arr) { }

JAVA please write this method

public static void recursiveSelectionSort(int[] arr) {

}

Solutions

Expert Solution

Answer -

Your code is here-

  • import java.util.Arrays;
  • class Great
  • {
  •    public static void swap(int[] array, int i, int j)
  •    {
  •        int t= array[i];
  •        array[i] = array[j];
  •        array[j] = t;
  •    }
  • public static void recursiveSelectionSort(int[] array, int i, int n) // // Recursive function for the sub-array arr[i..n-1]
  •    {
  •       
  •        int min = i;
  •        for (int j = i + 1; j < n; j++)
  •        {
  •           
  •            if (array[j] < array[min]) {
  •                min = j;   // modify index of min substance
  •            }
  •        }   
  •        swap(array, min, i);
  •        if (i + 1 < n) {
  •            recursiveSelectionSort(array, i + 1, n);
  •        }
  •    }
  •    public static void main(String[] args)
  •    {
  •        int array[] = { 2, 7, 11,0, 2, -1 };
  •        recursiveSelectionSort(array, 0, array.length);
  •        System.out.println(Arrays.toString(array)); //display the result
  •    }
  • }

screenshot of running program and output-'

Note- Please do upvote, if any problem then comment in box sure I will help.


Related Solutions

JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
JAVA please write this method public static void recursiveMergeSort(int[] arr) { }
Write a method public static void minMax(int[] arr) that takes an array of unique ints of...
Write a method public static void minMax(int[] arr) that takes an array of unique ints of length at least two as an argument, and swaps the smallest value of the array into the 0th position and swaps the largest value of the array into the last position. For example, if int[] a = {4, 3, 2, 6, 1, 5}, the method call minMax(a) should modify the array so that it is {1, 3, 2, 5, 4, 6}. The method should...
JAVA Given the header of a method public static void m1 (int[ ] max) Write down...
JAVA Given the header of a method public static void m1 (int[ ] max) Write down Java codes to invoke m1 method, declare variables as needed, (Do NOT implement the method)
Write a method with the following header: public static void showGradeDistribution(int a, int b, int c,...
Write a method with the following header: public static void showGradeDistribution(int a, int b, int c, int d, int f) It should print a graph (using asterisks) for each of the letters entered in the reverse order of the parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C and D and F, the message “Strong class!” should be displayed. For example a method call of: showGradeDistribution(5,7,4,4,3); Would...
   private static void merge(int arr[], int l, int m, int r) {        //...
   private static void merge(int arr[], int l, int m, int r) {        // Find sizes of two subarrays to be merged        int n1 = m - l + 1;        int n2 = r - m;        /* Create temp arrays */        int L[] = new int[n1];        int R[] = new int[n2];        /* Copy data to temp arrays */        for (int i = 0; i...
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an...
(java)Write a recursive method public static int sumForEachOther(Int n) that takes a positive Int as an argument and returns the sum for every other Int from n down to 1. For example, sumForEachOther(8) should return 20, since 8+6+4+ 2=20.And the call sumForEachOther(9) should return 25 since 9+7+5 + 3+1-=25. Your method must use recursion.
rite a method with the following header: public static void showGradeDistribution(int a, int b, int c,...
rite a method with the following header: public static void showGradeDistribution(int a, int b, int c, int d, int f) It should print a graph (using asterisks) for each of the letters entered in the reverse order of the parameter list and with a label. In addition, if A and B grades sum is equal or exceeds that of grades C and D and F, the message “Strong class!” should be displayed. For example a method call of: showGradeDistribution(5,7,4,4,3); Would...
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int...
Given the following method declaration, write a valid method call. public static void calcArea(String roomName, int length, int width)
public class Problem1 {    public static void partition(int[] A)    {        /*Rearrange the...
public class Problem1 {    public static void partition(int[] A)    {        /*Rearrange the array to have the following property:        Suppose the first element in the original array has the value x.        In the new array, suppose that x is in position i, that is data[i] = x.        Then, data[j] <= x for all j < I and data[j] > x for all j > i.        Thus, informally, all the...
Consider the following recursive method in Java public static int mystery(int n) {   if (n ==...
Consider the following recursive method in Java public static int mystery(int n) {   if (n == 0)   return 1;    else    return 4 * mystery (n - 1);   } What is the output of  mystery (3) using the code segment above Show your work on your trace file
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT