ava quick sort create a method to test that your quicksort( int [ ] a ), insertion sort and removeDuplicates( int [ ] methods work sufficiently. the code is below and it needs a method to test it  public class QuicksortTester  {      public static void quicksort(Comparable[] a) {     quicksort(a, 0, a.length - 1);   }   static void quicksort(Comparable[] a, int low, int high) {     int CUTOFF = 10;     if (low + CUTOFF > high)       insertionSort(a, low, high);     else {       int middle = (low + high) / 2;       if (a[middle].compareTo(a[low]) < 0)         swapReferences(a, low, middle);       if (a[high].compareTo(a[low]) < 0)         swapReferences(a, low, high);       if (a[high].compareTo(a[middle]) < 0)         swapReferences(a, middle, high);       swapReferences(a, middle, high - 1);       Comparable pivot = a[high - 1];       int i, j;       for (i = low, j = high - 1;;) {         while (a[++i].compareTo(pivot) < 0)           ;         while (pivot.compareTo(a[--j]) < 0)           ;         if (i >= j)           break;         swapReferences(a, i, j);       }       swapReferences(a, i, high - 1);       quicksort(a, low, i - 1);        quicksort(a, i + 1, high);     }   }   public static final void swapReferences(Object[] a, int index1, int index2) {     Object tmp = a[index1];     a[index1] = a[index2];     a[index2] = tmp;   }   private static void insertionSort(Comparable[] a, int low, int high) {     for (int p = low + 1; p <= high; p++) {       Comparable tmp = a[p];       int j;       for (j = p; j > low && tmp.compareTo(a[j - 1]) < 0; j--)         a[j] = a[j - 1];       a[j] = tmp;     }   }    static int removeDuplicates(int arr[], int n)     {         // Return, if array is empty         // or contains a single element         if (n==0 || n==1)             return n;                int[] temp = new int[n];                   // Start traversing elements         int j = 0;         for (int i=0; i

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

java quick sort

create a method to test that your quicksort( int [ ] a ), insertion sort and removeDuplicates( int [ ] methods work sufficiently.

the code is below and it needs a method to test it 

public class QuicksortTester  {
  

  public static void quicksort(Comparable[] a) {
    quicksort(a, 0, a.length - 1);
  }

  static void quicksort(Comparable[] a, int low, int high) {
    int CUTOFF = 10;
    if (low + CUTOFF > high)
      insertionSort(a, low, high);
    else {
      int middle = (low + high) / 2;
      if (a[middle].compareTo(a[low]) < 0)
        swapReferences(a, low, middle);
      if (a[high].compareTo(a[low]) < 0)
        swapReferences(a, low, high);
      if (a[high].compareTo(a[middle]) < 0)
        swapReferences(a, middle, high);

      swapReferences(a, middle, high - 1);
      Comparable pivot = a[high - 1];

      int i, j;
      for (i = low, j = high - 1;;) {
        while (a[++i].compareTo(pivot) < 0)
          ;
        while (pivot.compareTo(a[--j]) < 0)
          ;
        if (i >= j)
          break;
        swapReferences(a, i, j);
      }
      swapReferences(a, i, high - 1);

      quicksort(a, low, i - 1); 
      quicksort(a, i + 1, high);
    }
  }

  public static final void swapReferences(Object[] a, int index1, int index2) {
    Object tmp = a[index1];
    a[index1] = a[index2];
    a[index2] = tmp;
  }

  private static void insertionSort(Comparable[] a, int low, int high) {
    for (int p = low + 1; p <= high; p++) {
      Comparable tmp = a[p];
      int j;

      for (j = p; j > low && tmp.compareTo(a[j - 1]) < 0; j--)
        a[j] = a[j - 1];
      a[j] = tmp;
    }
  }
   static int removeDuplicates(int arr[], int n)
    {
        // Return, if array is empty
        // or contains a single element
        if (n==0 || n==1)
            return n;
      
        int[] temp = new int[n];
         
        // Start traversing elements
        int j = 0;
        for (int i=0; i<n-1; i++)
            // If current element is not equal
            // to next element then store that
            // current element
            if (arr[i] != arr[i+1])
                temp[j++] = arr[i];
         
        // Store the last element as whether
        // it is unique or repeated, it hasn't
        // stored previously
        temp[j++] = arr[n-1];  
         
        // Modify original array
        for (int i=0; i<j; i++)
            arr[i] = temp[i];
      
        return j;
    }
    
}

Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY