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

In java please do the following: Yes you may change isSorted 2 import stdlib.*;

ID: 3911575 • Letter: I

Question

In java please do the following: Yes you may change isSorted

2 import stdlib.*; 3 /IExercise 2.1.14 5 Complete the following method to sort a deck of cards, 6 with the restriction that the only allowed operations are to loolk 7at the values of the top two cards, to exchange the top two cards 8 and to move the top card to the bottom of the deck. 9 10 public class MyDeckSort f public static void sort (MyDeck d) t 12 13 14 15 16 17 18 19 20 21 /I TODO // You must sort the Deck using only the public methods of Deck // It should be sufficient to use the following: // d.sizeO / d.moveTopToBottom); // d.topGreaterThanNext(); // d.swapTopTwo(); // While debugging, you will want to print intermediate results. // You can use d.toString) for that: // stdOut.format ('Hz%-3d %s ", i, d.toString ()); 23 24 25private static void countops (MyDeck d) 26 27 28 29 30 31 32 private static double time; boolean print true; if (print) Stdout.println (d.toString ()); d.moveTopToBottom(); if (print) StdOut.println (d.toString ()); Stopwatch sw new Stopwatch ); sort (d) time sw.elapsedTime(); if (print) Stdout.println (d.toString )); d.isSorted (); 34 35 36 37public static void main (String[] args) 38 39 40 41 42 43 44 Y 45 46 int N- 10; MyDeck d new MyDeck (N); countops (d); //System.exit (0) //Comment this out to do a doubling test! double prevOpsd.ops); double prevTimetime; for (inti-o; i

Explanation / Answer

public static void sort(MyDeck d)

{

for(int i=0;i<d.size();i++)

{

for (int j = 0; j < d.size(); j++) //looping

{

if(d.topGreaterThanNext()) //if top is greater than next (a[i]>a[i+1])

d.swapToptwo(); //swap the two values

d.moveTopToBottom(); //chage the Top i=i+1

}

}

//after the loop the a[] will be sorted and top=0

}

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