Data Structures

profilekings12
parCheckerTest.py

from stack import Stack def parChecker(symbolString): s = Stack() balanced = True index = 0 while index < len(symbolString) and balanced: symbol = symbolString[index] if symbol == "(": s.push(symbol) else: if s.isEmpty(): balanced = False else: s.pop() index += 1 if balanced and s.isEmpty(): return True else: return False def main(): symbol = "(()()()())" print("Checking first: ", parChecker(symbol)) symbol = "()))" print("Checking second: ", parChecker(symbol)) symbol = "((((((())" print("Checking third: ", parChecker(symbol)) main()