-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathstack.py
More file actions
44 lines (32 loc) · 761 Bytes
/
Copy pathstack.py
File metadata and controls
44 lines (32 loc) · 761 Bytes
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
'''
栈
'''
class Stack(object):
# 初始化
def __init__(self):
self.__list = []
#添加元素
def push(self,element):
self.__list.append(element)
# 弹出元素
def pop(self):
if self.isEmpty():
return None
else:
return self.__list.pop()
#是否为空
def isEmpty(self):
return len(self.__list) == 0
def getSize(self):
return len(self.__list)
def __str__(self):
return " ".join(map(str, self.__list))
if __name__ == '__main__':
testStack = Stack();
testStack.push(1)
testStack.push(2)
testStack.push(3)
testStack.push(4)
print(testStack)
testStack.pop()
print(testStack)