Jump to content

[Resolvido] levelOrder


Recommended Posts


Eu tenho que implementar este algoritmo

Create a queue called nodes

Create an unordered list called results

Enqueue the root onto the nodes queue

While the nodes queue is not empty {

Dequeue the first element from the queue

If that element is not null

! ! Add that element to the rear of the results list

Enqueue the children of the element on the nodes queue


Add null on the result list


Return an iterator for the result list

public Iterator<T> levelorder() {
	ArrayUnorderedList<T> tempList = new ArrayUnorderedList<T>();
	QueueADT<T> queue = new LinkedQueue<T>();
	BinaryTreeNode<T> node = null;

	while (!queue.isEmpty()) {

		if (node != null) {
			if (node.left != null) {
			if (node.right != null) {
		} else {
	return tempList.iterator();

So que da-me este erro

Exception in thread "main" java.lang.NullPointerException

at estruturas_auxiliares.LinkedQueue.dequeue(LinkedQueue.java:132)

at ficha10.LinkedBinaryTree.levelorder(LinkedBinaryTree.java:202)

at estudar_exame.Estudar_Exame.main(Estudar_Exame.java:34)

Java Result: 1

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.