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

I need to create a quick sort array. It must sort random numbers. E.g: How can I

ID: 3760636 • Letter: I

Question

I need to create a quick sort array. It must sort random numbers.

E.g:

How can I make this code to work?

How do I avoid the indexoutofbound exception without changing the whole format?

How can I use Math.random instead of the user input?

Thanks!

Explanation / Answer

private E[] tofind; private int sameCounter=0; private int comparisions; public void quickSort() { quickInnerSort(0, tofind.length-1); System.out.println("George"); } /** * * @param st index of the starting point of the array * @param end index of the ending point of the array * @param k rank of the element to be found out */ private void quickInnerSort(int st, int end) { if(st>end) return; //printWithComparisions(); int cut = partition(st,end); //check k lies in which partition quickInnerSort(st,cut-1); quickInnerSort(cut+1,end); } /** * * @param st index of the array from where to partition * @param end index of the array till where to partition * @return index of the random number chosen to calculate */ private int partition(int st, int end) { int rand = (int) (st + (Math.random()*((end-st)+1))); //System.out.println("rand ="+tofind[rand]+" index at "+rand); E x = tofind[rand]; sameCounter=0; swap(end,rand); E x = tofind[end]; int i = st-1; for(int j=st;j
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