if(count == 4){
		qFinal.enqueue(q.peek());
		if(count3 == 0){
		System.out.println(qFinal);
		break;
	       }	
		else{			
		    sort(qFinal);
		}		
	}

this code is inside a while loop, and with the break statement, it should break out of the loop right? instead i think the program also executes the sort(qFinal) method b/c after it prints qFinal correctly, the program gives me an error.

Recommended Answers

All 4 Replies

Okay? So it gives you an error? And? How did you determine that this sort method had anything to do with it, or are you just guessing? Print the stacktrace of the error and read it. It will tell you exactly where the problem is. If you find yourself incapable of zeroeing in on the problem this way, then post the full stack trace here and more code, that little snippet above tells us nothing.

i guess break command should come after if block and before else.

after if and before else? you mean like this?

if ( valid ){
  // code if valid
}
break;
else{
  // code if not valid
}

looks to me like you're setting yourself up to get two problems..
1. you'll run the break no mather whether valid is true or not
2. I kind of think you'll run into an 'else without an if' error

Huh? Try again. Doing that would, of course, lead to an "else without if" compiler message. Please, don't guess, or at least try your guesses before posting them.

Edit: Damn! Too slow, again!

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.