forked from crisschan/emma_tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
60 lines (55 loc) · 1.18 KB
/
stack.py
File metadata and controls
60 lines (55 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#encoding=utf8
#!/usr/bin/env python
# __author_='crisschan'
# __data__='20161130'
# __from__='EmmaTools https://github.com/crisschan/EMMATools'
# __instruction__=栈的操作
class Stack(object):
def __init__(self):
self.items=[]
def isEmpty(self):
'''
返回是否为空
Returns: true 为空
false 不为空
'''
return len(self.items)==0
def push(self,item):
'''
入栈
Args:
item: 入栈的数据
Returns:null
'''
self.items.append(item)
def pop(self):
'''
出栈
Returns:null
'''
return self.items.pop()
def peek(self):
'''
查看栈顶对象而不移除它
Returns: 栈顶元素
'''
if not self.isEmpty():
return self.items[len(self.items)-1]
def size(self):
'''
计算站大小
Returns:长度
'''
return len(self.items)
'''
if __name__=="__main__":
s=Stack()
print s.isEmpty()
s.push('1')
print s.peek()
s.push(444)
print s.items
print s.size()
print s.pop()
print s.size()
'''