"""
Created on Tue Jun 26 22:32:27 2018
@author: luogan
"""
class Node(object):
def __init__(self,val=None,ne=None):
self.val=val
self.next=ne
class stack(object):
def __init__(self):
self.top=None
def peek(self):
if self.top!=None:
return self.top.val
else:
return None
def push(self,n):
n=Node(n)
n.ne=self.top
self.top=n
return n.val
def pop(self):
if self.top == None:
return None
else:
tmp=self.top.val
self.top=self.top.ne
return tmp
if __name__=="__main__":
s=stack()
s.push(1)
s.push(2)
s.push(3)
print (s.pop())
print (s.pop())
print (s.pop())
print('栈的一种更简单方式实现')
ss=[]
ss.append(1)
ss.append(2)
ss.append(3)
print(ss)
print (ss.pop())
print (ss.pop())
print (ss.pop())
3
2
1
栈的一种更简单方式实现
[1, 2, 3]
3
2
1