Question

This section of my code does not appear to be working. I feel like the problem might like with the stk.peek() sections of the code but I am not sure if this is true. Any ideas?

stk is my stack and the first thing read into the code is "("

if(stk.empty()==true || stk.peek()== "("){
    stk.push(post.get(i))      
    System.out.println("Test1:" +stk.peek());
}
Était-ce utile?

La solution

Try this. This should do it and has somewhat better style.

if (stk.empty() || "(".equals(stk.peek())){
    stk.push(post.get(i));     
    System.out.println("Test1:" + stk.peek());
}
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top