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);
			}
		}
	}

You compiled it and had a problem? Then post your error including the line number. .

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..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.