类似这样就可以了:   
                                                            a   
                                                          /   \   
                                                        b       c   
                                                      /   \   
                                                    d       e   
    
  最好每个节点画在一个圆圈里面 
    

解决方案 »

  1.   

    java 画图怎么传递要用的参数。。实在不懂。。哪位帮帮我。。
      

  2.   

    lz 的意思是polosh notation吗?
    例如输入:   1*2+3
         
      输出:     
                         +
                        / \
                       *   3
                      / \
                     1   2 
      

  3.   

    <<数据结构与算法>>java语言版
      

  4.   

    覆盖paintComponent(Graphics g)方法使用Graphics2D进行绘制, 圆和线都可以直接画出来, 但要精确地绘制一颗树, 需要你自己控制坐标, 如果是任意节点树, 估计计算坐标也是有一定难度的...
      

  5.   

    当画一个节点的时候样传入的是坐标X,Y和父节点的就可以了
    MiddleHead(TreeNode node, int x1, int y1, int x2, int y2, double alpha)
    node:表示当前的节点,
    x1,  y1 当前节点的父节点的坐标(父节点不存在的时候可以设为负数,然后在后面判断)
    x2,  y2 当前节点的坐标
    alpha表示父节点和当前节点连线的倾角(不能使用相同的角度,否则会出现2个节点重合的现象)
    下面是我在用的画图的方法,可以参考一下。
     public void MiddleHead(AVLTreeNode node, int x1, int y1, int x2, int y2, double alpha)//中根遍历并输出图形
            {
                if (node == null)
                    return;
                int x3 = x2 - (int)(myDraw.LineLength * Math.Sin(alpha));
                int y3 = y2 + (int)(myDraw.LineLength * Math.Cos(alpha));            int x4 = x2 + (int)(myDraw.LineLength * Math.Sin(alpha));
                int y4 = y2 + (int)(myDraw.LineLength * Math.Cos(alpha));
                double nextAngle = alpha * 3 / 5.0;
                MiddleHead(node.LeftChild, x2, y2, x3, y3, nextAngle);
                // Console.Write(node.Data);
                if (y1 > 0)
                {
                    int temx1 = 0;
                    int temy1 = 0;
                    int temx2 = 0;
                    int temy2 = 0;
                    double sita3 = Math.Asin((1.0) * (y2 - y1) / Math.Sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1)));//角度
                    double sita4 = Math.Acos((1.0) * (x2 - x1) / Math.Sqrt((y2 - y1) * (y2 - y1) + (x2 - x1) * (x2 - x1)));//角度
                    temx1 = x1 + (int)(myDraw.NodeRedius * Math.Cos(sita4));
                    temy1 = y1 + (int)(myDraw.NodeRedius * Math.Sin(sita3));
                    temx2 = x2 - (int)(myDraw.NodeRedius * Math.Cos(sita4));
                    temy2 = y2 - (int)(myDraw.NodeRedius * Math.Sin(sita3));
                    DrawLinkLine(temx1, temy1, temx2, temy2, myDraw.FrontColor, g);//画连接线
                }
                DrawNode(x2, y2, node.Data, myDraw.FrontColor);//画节点
                MiddleHead(node.RightChild, x2, y2, x4, y4, nextAngle);
            }