forked from meteor1993/python-learning
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackNode.py
More file actions
40 lines (35 loc) · 771 Bytes
/
Copy pathStackNode.py
File metadata and controls
40 lines (35 loc) · 771 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
class Node(object):
'''
节点实现
'''
def __init__(self,elem):
self.elem = elem
self.next = None
class Stack(object):
def __init__(self):
'''
初始化链表头
'''
self.__head = None
def is_empty(self):
return self.__head is None
def push(self, item):
'''
压栈
:param item:
:return:
'''
node = Node(item)
node.next = self.__head
self.__head = node
def pop(self):
'''
弹出栈
:return:
'''
if self.is_empty():
return
else:
p = self.__head
self.__head = p.next
return p.elem