Here's the first code that I had:
PHP Code:
for (int i = 0; i < array.length; i++) {
Object o1 = s.pop();
Object o2 = q.dequeue();
String num1 = (String) o1;
String num2 = (String) o2;
if (!num1.equals(num2)) {
result = "FALSE";
} else {
result = "TRUE";
}
}
I have no clue why does this get thrown:
Code:
Exception in thread "main" java.util.EmptyStackException
at java.util.Stack.peek(Unknown Source)
at java.util.Stack.pop(Unknown Source)
at MidtermPracticeMain.<init>(MidtermPracticeMain.java:48)
at MidtermPracticeMain.main(MidtermPracticeMain.java:104) I changed it to this one:
PHP Code:
for (int i = 0; i < s.size()-1; i++) {
if (!s.pop().equals(q.dequeue())) {
result = "FALSE";
} else {
result = "TRUE";
}
}
Exception doesn't get thrown, (but I still got logic error lol..)
My question is, how can they be different? What's wrong with the first one compared to the second one? Aren't they the same?

sigh... obviously not, but I still can't see the difference...