You should not have that while loop in function. You need to indent your code properly so that you can trace the logic correctly - you still have that final check for whether the stack is empty inside the for loop.
You should not have that while loop in function. You need to indent your code properly so that you can trace the logic correctly - you still have that final check for whether the stack is empty inside the for loop.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
you still have that final check for whether the stack is empty inside the for loop.
didnt get you???
should i remove the while??
If we properly format:
Now, it is obvious that this lies within the for loop:Code:int function() { for (int j = 0; j <10; j++) { if (name[j] =='(') { a.push(')'); } if (name[j]=='[') { a.push(']'); } if (name[j] == '{') { a.push('}'); } if (name[j] ==')' || name[j]=='}' || name[j]==']' ) { if (a.isEmpty()==0) { return 0; } if (a.pop()!= name[j] ) return 0; } if (!a.isEmpty()) { return 0; } else return 1; } }
Therefore, the for loop never makes it past the first iteration, i.e., it never considers any more than the first character. If that first character is an opening bracket, the stack is not empty, at the end of the loop, so it returns 0, even if the next character is a closing bracket.Code:if (!a.isEmpty()) { return 0; } else return 1;
But the point behind this is to check, after everything has been processed, whether the stack is empty. If at that point the stack is empty, then all is well.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
i put that thing out ov for loop but its still not working ,, =((
Thanks Problem solved,,
specially to ANON, ROCKY MARRONE, LASERLIGHT