Skip to content

fixed balanced_parentheses, Added infix-prefix & postfix evaluation #621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 1, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update balanced_parentheses.py
  • Loading branch information
ashwek authored Nov 30, 2018
commit 1b0fbe39118397bb283878733539295707285b87
6 changes: 4 additions & 2 deletions data_structures/stacks/balanced_parentheses.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import print_function
from __future__ import absolute_import
from .Stack import Stack
from stack import Stack

__author__ = 'Omkar Pathak'

Expand All @@ -12,8 +12,10 @@ def balanced_parentheses(parentheses):
if parenthesis == '(':
stack.push(parenthesis)
elif parenthesis == ')':
if stack.is_empty():
return False
stack.pop()
return not stack.is_empty()
return stack.is_empty()


if __name__ == '__main__':
Expand Down