-3

// Trying to return a list containing the values in 'a' by traversing the nodes in postorder. In Junit it says that "String cannot be cast to List". Help please.

public static List postorder(Tree a) {
        if (a.getEmpty()) 
            return List.empty(); 
        else
              postorder(a.getLeft());
              postorder(a.getRight());

              return ListOps.append(postorder(a.getLeft()), 
                        List.cons(a.getValue(), postorder(a.getRight())));
            }
  • Please read this: http://stackoverflow.com/help/how-to-ask And at least add your exception – Teo Jan 24 '16 at 23:50
  • Give us a hint about your problem. What makes you think that something is indeed wrong with your code? – PM 77-1 Jan 24 '16 at 23:50
  • What does `ListOps.append(...)` return? From your error, I'd make a strong guess it returns a `String`, while your method returns a `List`. – Ian Jan 25 '16 at 00:39

1 Answers1

1

I think the problem is here: ListOps.append(.. I say probably because your question is totally unclear, so I think that ListOps is a String, but your method return List...

So use a ArrayList or another class that implement List, and add the elements into it...

Teo
  • 3,143
  • 2
  • 29
  • 59