001package algs21;
002import stdlib.*;
003import algs12.XCard;
004
005public class XSortCards3 {
006        public static void show (String title, XCard[] d) {
007                StdOut.println (title);
008                for (int i=0; i<4; i++) {
009                        for (int j=0; j<13; j++) {
010                                StdOut.format ("%3s ", d[i*13+j]);
011                        }
012                        StdOut.println ();
013                }
014                StdOut.println ();
015        }
016        public static void main (String[] args) {
017                XCard[] d = XCard.newDeck ();
018                show ("Initial", d);
019                StdRandom.shuffle (d);
020                show ("Shuffled", d);
021                Insertion.sort (d);
022                show ("Sort1", d);
023                Insertion.sort (d, (XCard c1, XCard c2) -> {
024                        if (c1.rank.compareTo (c2.rank) < 0) return -1;
025                        if (c1.rank.compareTo (c2.rank) > 0) return +1;
026                        if (c1.suit.compareTo (c2.suit) < 0) return -1;
027                        if (c1.suit.compareTo (c2.suit) > 0) return +1;
028                        return 0;
029                });
030                show ("Sort2", d);
031        }
032}