-
Notifications
You must be signed in to change notification settings - Fork 0
/
Node.py
28 lines (22 loc) · 952 Bytes
/
Node.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
class Node:
def __init__(self, node):
self.id = node
self.adjacent = {}
# adds adjacent node id to this node's adjacency list
def add_adjacent(self, adjacent_node, weight=0, label=''):
self.adjacent[adjacent_node] = [weight, label]
# deletes adjacent node id from this node's adjacency list
def del_adjacent(self, adjacent_node):
self.adjacent.pop(adjacent_node)
# gets this node's adjacency list
def get_adjacents(self):
return self.adjacent.keys()
# gets this node's id (each id is unique to the node)
def get_node_id(self):
return self.id
# gets the weight of the edge connecting this node to one of its adj
def get_weight(self, adjacent_node):
return self.adjacent[adjacent_node][0]
# gets the label of the edge connecting this node to one of its adj
def get_label(self, adjacent_node):
return self.adjacent[adjacent_node][1]