Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a method called sort(int[] v) which takes an integer arrayand sorts the ar

ID: 3617526 • Letter: W

Question

Write a method called sort(int[] v) which takes an integer arrayand sorts the array in increasing order. Note that the methodshould sort the array given, not create any new arrays. Also, youMUST write the method recursively to get any marks. You will wantto use a helper method.

(Hint: Move left to right through the array recursively, swapping apair of elements if the one on the left is larger than the one onthe right. Use a parameter to keep track of the position of theelement pair that you are examining. If you reach the end of thearray and no items have been swapped, then the array is sorted nowand you can stop. Otherwise, you will need to restart the swappingprocess from the beginning of the array. You'll need to keep trackof whether or not you made a swap...use another parameter).

It may be helpful to write a method that will display your array,so that you can use this for debugging. Here is an example of howto test it from a main method, assuming that you have a methodcalled displayArray to display the array:

int[] v = {3, 6, 9, 2, 7, 1, 5, 8, 4, 2, 2, 1};

sort(v);

displayArray(v)

Explanation / Answer

public class bubbleSort{ public static void main(String a[]){     int i;     int[] v = {3, 6, 9, 2, 7, 1, 5, 8, 4, 2, 2,1};     System.out.println("Values Before thesort: ");     for(i = 0; i
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote