现在的位置: 首页 > 综合 > 正文

模拟树结构读取

2013年10月04日 ⁄ 综合 ⁄ 共 802字 ⁄ 字号 评论关闭

模拟树结构读取

public class Test
{

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        //树结构数据
        String str[][] = new String[][]
        {
            { "1", "0", "ss" },
            { "2", "1", "ss" },
            { "3", "1", "ss" },
            { "4", "1", "ss" },
            { "5", "2", "ss" },
            { "6", "2", "ss" },
            { "7", "3", "ss" },
            { "8", "3", "ss" },
            { "9", "3", "ss" },
            { "10", "5", "ss" },
            { "11", "5", "ss" },
            { "12", "5", "ss" },
        };
        readTree(str, "1");

    }
   
    public static  void readTree(String str[][],String father)
    {
        for (int i = 0; i < str.length; i++)
        {
            if(str[i][1].equals(father))
            {
                System.out.println(str[i][1]+" | "+str[i][0]);
                //递归调用
                readTree(str, str[i][0]);
            }
        }

    }

抱歉!评论已关闭.