Question d’entretien chez Google

Print BST by level

Réponse à la question d'entretien

Utilisateur anonyme

24 avr. 2012

In Java (you call this method with the root): void printBFS(Node s){ Queue q = new Queue(); q.add(s); while (!q.isEmpty()){ Node tmp = (Node)q.remove(); System.out.print(tmp.data + " "); if (tmp.right!=null) q.add(tmp.right); if (tmp.left !=null) q.add(tmp.left ); } }