private static void show(double[] a, int i, int j) { StdDraw.setYscale(-a.length + i + 1, i); StdDraw.setPenColor(StdDraw.LIGHT_GRAY); for (int k = 0; k < j; k++) StdDraw.line(k, 0, k, a[k] * .6); StdDraw.setPenColor(StdDraw.BOOK_RED); StdDraw.line(j, 0, j, a[j] * .6); StdDraw.setPenColor(StdDraw.BLACK); for (int k = j + 1; k < i; k++) StdDraw.line(k, 0, k, a[k] * .6); StdDraw.setPenColor(StdDraw.LIGHT_GRAY); for (int k = i + 1; k < a.length; k++) StdDraw.line(k, 0, k, a[k] * .6); }
// test client public static void main(String[] args) { // parse command-line argument as an array of 1-character strings String s = "EASYQUESTION"; int N = s.length(); String[] a = new String[N]; for (int i = 0; i < N; i++) a[i] = s.substring(i, i + 1); // set canvas size StdDraw.setCanvasSize(30 * (N + 3), 30 * (N + 3)); StdDraw.setXscale(-3, N + 1); StdDraw.setYscale(N + 1, -3); StdDraw.setFont(new Font("SansSerif", Font.PLAIN, 13)); // draw the header header(a); // sort the array sort(a); // draw the footer footer(a); }