包含TreeNode的Array的ArrayList

时间:2015-04-29 16:55:24

标签: java arrays arraylist tree binary-tree

我想创建一个由treeNodes组成的数组Arraylist。我的试验是

My Survey.php 


    <?php

    $link = mysqli_connect("localhost","student","student");
    mysqli_select_db($link,"gpdb");


    //question 1
    $query = "SELECT * from gp";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?>

    <div class="Circuits">
    <h1>Which Grand Prix's are closest to you<h1>
    <form action="<?php $_SERVER['PHP_SELF']; ?>" method="get" >
    <p>Option 1</p>
    <select name="GrandPrix">
    <?php do { ?>    
                <option value="<?php echo $row['Circuits'];  ?>"><?php echo                        
    $row['Circuits'];  ?></option>
            <?php } while ($row = mysqli_fetch_assoc($result)); ?>
         </select>


    <?php
    $query = "SELECT * from gp";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?>


    <p>Option 2</p>
    <select name="GrandPrix2">
    <?php do { ?>    
                <option value="<?php echo $row['Circuits'];  ?>"><?php echo           
    $row['Circuits'];  ?></option>
        <?php } while ($row = mysqli_fetch_assoc($result)); ?>
    </select>

    <?php
    $query = "SELECT * from gp";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?> 

    <p>Option 3</p>
    <select name="GrandPrix3">
    <?php do { ?>    
                <option value="<?php echo $row['Circuits'];  ?>"><?php echo         
    $row['Circuits'];  ?></option>
        <?php } while ($row = mysqli_fetch_assoc($result)); ?>
    </select><br />
    </form>
    </div>

    <?php
    $query = "SELECT * from place";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result); 
    ?>

    <div class="Country"
    <h1>What countries would you like to visit?</h1>
    <p>Country 1</p>
    <select name="Country1">
    <?php do { ?>
        <option value="<?php echo $row['Location']; ?>"><?php echo     
    $row['Location']; ?></option>
            <?php } while ($row = mysqli_fetch_assoc($result)); ?>
      </select>

    <?php
    $query = "SELECT * from place";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result); 
    ?>
    <p>Country 2</p>
    <select name="Country1">
    <?php do { ?>
        <option value="<?php echo $row['Location']; ?>"><?php echo     
    $row['Location']; ?></option>
            <?php } while ($row = mysqli_fetch_assoc($result)); ?>
      </select>
    </div>



    <?php
    $query = "SELECT * from month";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?>

    <div class="month">
    <h1>When are you available to go to a grand prix</h1>
     <p>Month 1</p>
    <select name="Month">
    <?php do { ?>    
                <option value="<?php echo $row['monthofgp'];  ?>"><?php echo     
      $row['Location']; ?></option>
        <?php } while ($row = mysqli_fetch_assoc($result)); ?>
    </select>

    <?php
    $query = "SELECT * from month";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?>
    <p>Month 2</p>
    <select name="Month">
    <?php do { ?>    
                <option value="<?php echo $row['monthofgp'];  ?>"><?php echo     
    $row['monthofgp'];  ?></option>
        <?php } while ($row = mysqli_fetch_assoc($result)); ?>
    </select>

    <?php
    $query = "SELECT * from month";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?>
    <p>Month 3</p>
    <select name="Month">
    <?php do { ?>    
                <option value="<?php echo $row['monthofgp'];  ?>"><?php echo 
   $row['monthofgp'];  ?></option>
        <?php } while ($row = mysqli_fetch_assoc($result)); ?>
    </select><br />
     </div>


    <div class="Driver">   
    <?php
    $query = "SELECT * from teamName";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?>

    <h1>What is favourite team?</h1>

     <p>Team</p>
    <select name="taem">
    <?php do { ?>    
                <option value="<?php echo $row['Team'];  ?>"><?php echo 
    $row['Team'];  ?></option>
        <?php } while ($row = mysqli_fetch_assoc($result)); ?>
    </select><br />
    </div>



    <div class="Driver">
    <?php
    $query = "SELECT * from driverName";
    $result = mysqli_query($link,$query);
    $row = mysqli_fetch_assoc($result);
    ?>

    <h1>Who is your favourite driver?</h1>

     <p>Driver</p>
     <select name="taem">
    <?php do { ?>    
                <option value="<?php echo $row['Driver'];  ?>"><?php echo    
    $row['Driver'];  ?></option> 
        <?php } while ($row = mysqli_fetch_assoc($result)); ?>
        </select><br />
    </div>


    <input type="submit" />
    <input type="reset" />

    </form> 

但它给出了一个错误。 (包括utils)

写这个的正确方法是什么?我的目标是在二叉树中找到节点的最小深度(只是为了找到最小的不找到该节点本身,我将水平放入arraylist,一旦大小不是2 ^ j,那么最小级别是j-1 )。

提前致谢,任何帮助/提示/解决方案......

2 个答案:

答案 0 :(得分:3)

Arrays类是一个util类,而不是您用于数组的类型。 Arrays类从不采用泛型参数,这是您的错误告诉您的。

如果你想要一个包含数组的ArrayList,那么你可能正在寻找这样的东西:

ArrayList<TreeNode[]> aList = new ArrayList<>();

答案 1 :(得分:3)

List<TreeNode[]> myList = new ArrayList<TreeNode[]>();

TreeNode[] aNodes = new TreeNode[fixedSizeArray];

这就是你可以创建数组和数组列表的方法..根据你的描述,我建议,参考一些像OSPF等微笑的东西的java例子。看看使用了什么样的数据结构以及如何使用。