Delete balance_parenthesis.py

This commit is contained in:
bt3 2015-10-25 20:15:33 -07:00
parent b7f8e031c3
commit b240b35433

View File

@ -1,41 +0,0 @@
#!/usr/bin/env python
__author__ = "bt3"
''' use a stack to balance the parenteses of a string '''
from stack import Stack
def balance_par_str_with_stack(str1):
s = Stack()
balanced = True
index = 0
while index < len(str1) and balanced:
symbol = str1[index]
if symbol == "(":
s.push(symbol)
else:
if s.isEmpty():
balanced = False
else:
s.pop()
index = index + 1
if balanced and s.isEmpty():
return True
else:
return False
if __name__ == '__main__':
print(balance_par_str_with_stack('((()))'))
print(balance_par_str_with_stack('(()'))