Empty output while performing level order traversal in Binary trees in Java
As you want to collect the results in ourList
, you need to create dedicated instances of the lists kept in ourArray
. So, instead of clearing ourArray
, you should probably re-create it: Instead of
ourArray.clear();
write
ourArray= new ArrayList<>();