-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack.py
More file actions
82 lines (65 loc) · 1.89 KB
/
Copy pathstack.py
File metadata and controls
82 lines (65 loc) · 1.89 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"""
@version: python3.6
@author: Fieldhunter
@contact: 1677532160yuan@gmail.com
@time: 2020-05-03
"""
import functools
"""
Check if the code used to access the stack information,Decorator function.
The purpose of simply adding code is to prevent stack from
being tampered with maliciously and to provide the API for developers.
"""
def check_code(func):
@functools.wraps(func)
def check(self, code):
if code != 'adsf;{h3096j34ka`fd>&/edgb^45:6':
raise Exception('code is wrong!')
result = func(self, code)
return result
return check
class Sequence_stack():
def __init__(self):
self.__data_list = []
self.__num = 0
def add_data(self, element):
self.__data_list.append(element)
self.__num += 1
def pop_data(self):
if self.__data_list != []:
last_data = self.__data_list[-1]
del self.__data_list[-1]
self.__num -= 1
return last_data
else:
print("No data in stack")
return None
@check_code
def return_basic_information(self, code):
return self.__data_list, self.__num
# linked stack
class link_Node():
def __init__(self, num):
self.data = num
self.next = None
class Linked_stack():
def __init__(self):
self.__head = None
self.__num = 0
def add_data(self, element):
new_data = link_Node(element)
new_data.next = self.__head
self.__head = new_data
self.__num += 1
def pop_data(self):
if self.__head != None:
last_data = self.__head.data
self.__head = self.__head.next
self.__num -= 1
return last_data
else:
print("No data in stack")
return None
@check_code
def return_basic_information(self, code):
return self.__head, self.__num