-
Notifications
You must be signed in to change notification settings - Fork 0
/
listnode.py
67 lines (53 loc) · 1.59 KB
/
listnode.py
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
from typing import List
class ListNode:
def __init__(self, val: any, depth: int = 0, cost: int = 0, parent=None, next_n=None, cousin=None):
"""
树节点的二叉树表示
:type val: any
:type parent: ListNode
:type next_n: ListNode
:type cousin: ListNode
:param val: 节点值
:param depth: 节点深度
:param cost: 节点代价
:param parent: 父节点
:param next_n: 子节点
:param cousin: 兄弟节点
"""
self._val = val
self._cost = cost
self._parent = parent
self._depth = depth
self._next = next_n
self._cousin = cousin
def get_cost(self) -> int:
return self._cost
def get_depth(self) -> int:
return self._depth
def get_f(self) -> int:
return self._cost + self._depth
def get_val(self):
return self._val
def get_parent(self) -> __init__:
return self._parent
def get_next(self) -> __init__:
return self._next
def get_cousin(self) -> __init__:
return self._cousin
def set_next(self, next_n):
self._next = next_n
def set_cost(self, cost):
self._cost = cost
def set_depth(self, depth):
self._depth = depth
def set_cousin(self, cousin):
self._cousin = cousin
def get_road(self) -> List[__init__]:
road = list()
now = self
while now.get_parent() is not None:
road.append(now)
now = now.get_parent()
road.append(now)
road.reverse()
return road