• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dijkstra’s Two-Stack  RSS feed

 
Andrei Gabi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What's wrong with my code? I want to calculate this ( 10 + ( ( 9 + 8 ) * ( 7 * 6 ) ) ),but the result doesn't show up.


 
Paul Mrozik
Ranch Hand
Posts: 117
Chrome Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please fix your code as it doesn't compile. What error message are you getting?
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The easiest thing to do it put a bunch of System.out.println statements in there to see what it is really doing. print out what you think you get. print out what you are comparing. print out what you are pushing onto the stack each time. Print which if/else block you fall into.

it's quick, it's easy, and it's something you can do do figure out the problem yourself in about 5 minutes.
 
Andrei Gabi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I exit a while loop?I want to print this line of code:
41 System.out.println(vals.pop());
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Andrei Gabi wrote:How do I exit a while loop?I want to print this line of code:
41 System.out.println(vals.pop());

What do you mean you want to "print this line of code"? That line should print whatever is popped off the stack.

if you want to exit a loop, you have a few options:

1) use a break statement - although this is often frowned upon
2) set a flag and use it as an additional condition of the loop
3) ...

or, you could explain in detail what you really WANT to do, rather than asking HOW to do something (that may not be the right thing).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!