简体   繁体   中英

inorder traversal of a BST and adding it to a list

I have written the following code, i think there is an issue somewhere with the parameters. I can't seem to find it. I am using a custom import which has .getLeftChild() and so on which should be pretty easy to figure out.

  ArrayList<E> L = new ArrayList<E>();
    BTreeNode<E> n = T.getRoot();

   if(n==null) {
       return L;

   }else{

   sisäjärjestysKulku(n, L);   <---- refers to missing type <E>
   }
   return L;
}


private static void sisäjärjestysKulku(BTreeNode <E> n, ArrayList<E> L) { <--

    // base case:
    if (n == null) 
    return;
    // reduction:

    sisäjärjestysKulku(n.getLeftChild(), L);
    L.add(n.getElement());
    sisäjärjestysKulku(n.getRightChild(),L);

}

How would one fix this so it works. Added arrows to where Eclipse gives me an error. I am hoping for a solution that would keep this structure.

似乎您错过了方法声明中的类型参数,请尝试:

private static <E> void sisäjärjestysKulku(BTreeNode<E> n, ArrayList<E> L) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM