levelOrder
em nossa árvore chamada levelOrder
. Esse método deve retornar uma matriz contendo os valores de todos os nós da árvore, explorados de uma maneira abrangente. Certifique-se de retornar os valores na matriz, não os próprios nós. Um nível deve ser percorrido da esquerda para a direita. Em seguida, vamos escrever um método semelhante chamado reverseLevelOrder
que realiza a mesma pesquisa, mas na direção inversa (direita para esquerda) em cada nível. BinarySearchTree
existe.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() }; return (typeof test == "object")})(), "The BinarySearchTree
data structure exists.");'
- text: A árvore de pesquisa binária tem um método chamado levelOrder
.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.levelOrder == "function")})(), "The binary search tree has a method called levelOrder
.");'
- text: A árvore de pesquisa binária tem um método chamado reverseLevelOrder
.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; return (typeof test.reverseLevelOrder == "function")})(), "The binary search tree has a method called reverseLevelOrder
.");'
- text: O método levelOrder
retorna uma matriz dos valores do nó da árvore explorados em ordem de nível.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.levelOrder !== "function") { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.levelOrder().join("") == "719038102546"); })(), "The levelOrder
method returns an array of the tree node values explored in level order.");'
- text: O método reverseLevelOrder
retorna uma matriz dos valores do nó da árvore explorados na ordem inversa do nível.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.reverseLevelOrder !== "function") { return false; }; test.add(7); test.add(1); test.add(9); test.add(0); test.add(3); test.add(8); test.add(10); test.add(2); test.add(5); test.add(4); test.add(6); return (test.reverseLevelOrder().join("") == "791108305264"); })(), "The reverseLevelOrder
method returns an array of the tree node values explored in reverse level order.");'
- text: O método levelOrder
retorna null
para uma árvore vazia.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.levelOrder !== "function") { return false; }; return (test.levelOrder() == null); })(), "The levelOrder
method returns null
for an empty tree.");'
- text: O método reverseLevelOrder
retorna null
para uma árvore vazia.
testString: 'assert((function() { var test = false; if (typeof BinarySearchTree !== "undefined") { test = new BinarySearchTree() } else { return false; }; if (typeof test.reverseLevelOrder !== "function") { return false; }; return (test.reverseLevelOrder() == null); })(), "The reverseLevelOrder
method returns null
for an empty tree.");'
```