def reverse(string):
    myStack = Stack(len(string))
    for i in string:
        myStack.push(i)
    result = ""
    while not myStack.isEmpty():
        result += myStack.pop()
    return result
Example #2
0
def dtob(decimal, base = 2):
    myStack = Stack()
    while decimal > 0:
        myStack.push(decimal % base)
        decimal //= base # 나머지
    result = ""
    while not myStack.isEmpty():
        result += str(myStack.pop())
    return result
def parseParenthesis(string):
    balanced = 1
    index = 0
    myStack = Stack(len(string))
    while (index < len(string)) and (balanced == 1):
        check = string[index]
        if check == "(":
            myStack.push(check)
        else:
            if myStack.isEmpty():
                balanced = 0
            else:
                myStack.pop()
        index += 1

    if balanced == 1 and myStack.isEmpty():
        return True
    else:
        return False