hello,

can u pls help me sir about my problem in the level order travelsal?... i did trace my code and i found no wrong. but when i compile it, there's something wrong in it and i dont know where...

thank u very much!

int count = 1;
	public void levelorderTraversal(BinaryTree input) throws Exception{
		System.out.print(input.root + " ");
		BinaryTree yes = new BinaryTree();
		BinaryTree temp;
		Queue queue = new Queue();
		queue.enqueue(input.leftSubTree);
		queue.enqueue(input.rightSubTree);
		if(queue.isEmpty()){
			return;
		}else{
			if(count == 1){
				temp = (BinaryTree) queue.dequeue();
				count = 2;
				yes.levelorderTraversal(temp);
			}else if(count == 2){
				temp = (BinaryTree) queue.dequeue();
				count = 1;
				yes.levelorderTraversal(temp);
			}
		}
	}

hello,

can u pls help me sir about my problem in the level order travelsal?... i did trace my code and i found no wrong. but when i compile it, there's something wrong in it and i dont know where...

thank u very much!

int count = 1;
	public void levelorderTraversal(BinaryTree input) throws Exception{
		System.out.print(input.root + " ");
		BinaryTree yes = new BinaryTree();
		BinaryTree temp;
		Queue queue = new Queue();
		queue.enqueue(input.leftSubTree);
		queue.enqueue(input.rightSubTree);
		if(queue.isEmpty()){
			return;
		}else{
			if(count == 1){
				temp = (BinaryTree) queue.dequeue();
				count = 2;
				yes.levelorderTraversal(temp);
			}else if(count == 2){
				temp = (BinaryTree) queue.dequeue();
				count = 1;
				yes.levelorderTraversal(temp);
			}
		}
	}

ok, tnx.. uhm, i got the right code already..

compliments from my classmates..hehe

public void levelorderTraversal(BinaryTree input) throws Exception{
		Queue queue = new Queue();
		queue.enqueue(input);
		while(!queue.isEmpty()){
	    		BinaryTree yes = (BinaryTree)queue.dequeue();
			System.out.print(yes.root + " ");
			if(yes.leftSubTree!=null){
				queue.enqueue(yes.leftSubTree);
			}
			if(yes.rightSubTree!=null){
				queue.enqueue(yes.rightSubTree);
			}	
		}
	}

again, thank you.. 'til next time..

This question has already been answered. Start a new discussion instead.