class StackReverse:
def reverseStack(self, A, n):
if n == 0:
return
else:
i = self.get(A)
self.reverseStack(A,n-1)
A.append(i)
return A
# get函数实现了将栈底的元素从栈中弹出并删除
def get(self,A):
result = A.pop()
if len(A) == 0:
return result
else:
last = get(A)
A.append(result)
return last
网友评论