小编sim*_*nks的帖子

这种Python后缀符号(反向波兰表示法)解释器可以更有效和准确吗?

这是一个Python后缀符号解释器,它使用堆栈来计算表达式.是否可以使此功能更有效和准确?

#!/usr/bin/env python


import operator
import doctest


class Stack:
    """A stack is a collection, meaning that it is a data structure that 
    contains multiple elements.

    """

    def __init__(self):
        """Initialize a new empty stack."""
        self.items = []       

    def push(self, item):
        """Add a new item to the stack."""
        self.items.append(item)

    def pop(self):
        """Remove and return an item from the stack. The item 
        that is returned is always the last one that was added.

        """
        return self.items.pop()

    def is_empty(self):
        """Check whether the stack is …
Run Code Online (Sandbox Code Playgroud)

python rpn postfix-notation

7
推荐指数
1
解决办法
6407
查看次数

标签 统计

postfix-notation ×1

python ×1

rpn ×1