문제

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());
}
도움이 되었습니까?

해결책

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());
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top