예제 #1
0
    def setUp(self):
        # Provide an empty stack
        self.stack = MyStack()

        # Provide a filled stack
        self.len_test_data = 5
        self.test_data = [i + 1 for i in range(self.len_test_data)]
        self.filled_stack = MyStack()
        for i in self.test_data:
            self.filled_stack.push(i)
예제 #2
0
def rpn(expression):
    # operand: sayi
    # operation: islem
    operations = ['+', '*', '-', '/']
    elements = expression.split()
    stack = MyStack()

    for e in elements:
        if e in operations:
            num2 = stack.pop()
            num1 = stack.pop()

            if e == '+':
                result = num1 + num2
            elif e == '*':
                result = num1 * num2
            elif e == '-':
                result = num1 - num2
            else:
                result = num1 / num2

            stack.push(result)
        else:
            num = int(e)
            stack.push(num)

    print(stack.pop())
예제 #3
0
 def test_is_empty(self):
     stack = MyStack()
     self.assertTrue(stack.is_empty())
     stack.push(1)
     self.assertFalse(stack.is_empty())
     stack.pop()
     self.assertTrue(stack.is_empty())
예제 #4
0
def main():
    """main関数"""

    mystack = MyStack(STACK_SIZE)  # インスタンス化

    mystack.pushdown('a')  # データ入力
    mystack.pushdown('b')
    mystack.pushdown('c')

    while (not mystack.isempty()):  # データ出力
        print(mystack.popup())
예제 #5
0
#!/usr/bin/env python3

import os
from aws_cdk import core

from my_stack import MyStack

app = core.App()
MyStack(app,
        "s3-lambda-ecs",
        env={
            "region": "us-east-1",
            "account": os.environ["CDK_DEFAULT_ACCOUNT"],
        })

app.synth()
예제 #6
0
 def __init__(self):
     self.latest = MyStack()
     self.oldest = MyStack()
예제 #7
0
 def test_instantiation(self):
     stack = MyStack()
     self.assertEqual(None, stack.top)
     self.assertEqual(0, len(self.stack))