import java.util.*; public class TreeDraw { public static void treeDraw(int depth,double x,double xLow,double xHi,double y,double dY){ StdDraw.filledCircle(x,y,0.005); if (depth == 0) return; double xLeft = (xLow + x)/2.0; double xRight = (x + xHi)/2.0; StdDraw.line(x,y,xLeft,y+dY); StdDraw.line(x,y,xRight,y+dY); treeDraw(depth-1,xLeft,xLow,x,y+dY,dY); treeDraw(depth-1,xRight,x,xHi,y+dY,dY); } public static void main(String[] args){ String commands = "\nTreeDraw (version 2.7182) \n" + "btree (bt), htree (ht), help, quit (q)"; System.out.println(commands); Scanner sc = new Scanner(System.in); System.out.print("> "); String command = sc.next(); while (!command.equals("quit") && !command.equals("q")){ if (command.equals("help")) System.out.println(commands); if (command.equals("btree") || command.equals("bt")){ System.out.print("height>> "); StdDraw.clear(); int n = sc.nextInt(); treeDraw(n,0.5,0.0,1.0,1.0,-0.1); } if (command.equals("htree") || command.equals("ht")){ System.out.print("frequency>> "); StdDraw.clear(); int n = sc.nextInt(); Htree.draw(n,0.5,0.5,0.5); } System.out.print("> "); command = sc.next(); } System.exit(0); } }