MCPcopy Index your code
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / parChecker

Function parChecker

Stack.py:53–73  ·  view source on GitHub ↗
(symbolString)

Source from the content-addressed store, hash-verified

51
52# 利用栈判断括号平衡Balanced parentheses
53def parChecker(symbolString):
54 s = Stack()
55 balanced = True
56 index = 0
57 while index < len(symbolString) and balanced:
58 symbol = symbolString[index]
59 if symbol in '([{':
60 s.push(symbol)
61 else:
62 if s.isEmpty():
63 balanced = False
64 else:
65 top = s.pop()
66 if not matches(top, symbol):
67 balanced = False
68 index += 1
69
70 if balanced and s.isEmpty():
71 return True
72 else:
73 return False
74
75def matches(open, close):
76 opens = '([{'

Callers

nothing calls this directly

Calls 5

pushMethod · 0.95
isEmptyMethod · 0.95
popMethod · 0.95
StackClass · 0.85
matchesFunction · 0.85

Tested by

no test coverage detected