-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathnode.py
More file actions
28 lines (23 loc) · 876 Bytes
/
node.py
File metadata and controls
28 lines (23 loc) · 876 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
# Create here the Node Class
from typing import List, Optional
class Node:
id: int
parent: int
def __init__ (self, id:int, parent: int):
if not isinstance(id, int) or (parent is not None and not isinstance(parent, int)):
raise ValueError("Os ids devem ser inteiros")
if parent > id:
raise ValueError("O id do pai deve ser menor que o id do Node")
if parent == id:
raise ValueError("O id do pai não pode ser igual ao id do Node")
self.id = id
self.parent = parent
def __repr__(self):
return f"Node({self.id}, {self.parent})"
def __eq__(self, other):
if isinstance(other, Node):
return self.id == other.id and self.parent == other.parent
return False
def __hash__(self):
return hash((self.id, self.parent))
pass