class Stack:
def __init__(self):#创建一个空
self.items = []
def isEmpty(self):#判断返回栈是否为空
return self.items == []
def push(self, item):#将一个item加入栈顶
self.items.append(item)
def pop(self):#查看栈顶数据,看完后删除
return self.items.pop()
def peek(self):#查看栈顶数据,但不对其做修改
return self.items[len(self.items)-1]
def size(self):#返回栈中的数据个数
return len(self.items)
def transform(string):
compare = {}
compare["*"] = 3
compare["/"] = 3
compare["+"] = 2
compare["-"] = 2
compare["("] = 1
record_mark_stack = Stack()#储存字符的栈
output_stack= []#输出数的数组
# tokenList = string.split()#以空格为隔开符将表达式分为切片
tokenList = list(string)
print(tokenList)
for token in tokenList:
print('当前轮到',token)
if token in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnobprstuv
10以内计算python
最新推荐文章于 2023-11-17 08:44:29 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)