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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
