This commit is contained in:
Medium Fries
2019-03-15 01:26:26 -07:00
parent fa12687849
commit ea2aa8d2a6
17 changed files with 415 additions and 0 deletions

View File

53
370/samples/graph.py Executable file
View File

@@ -0,0 +1,53 @@
#!/usr/bin/python3
import random
class Node:
def __init__(self, data:int):
self.data = data
# empty list o rama
self.refs = []
def __str__(self):
return f'{self.data}:{self.refs}'
def new_node(data):
"""
Provides a new node for a ref list or a basic s
"""
return Node(data)
def add_node(base, data):
"""
Creates a new node for the base node to hook onto
"""
base.refs.append(new_node(data))
def show_children(node):
"""
LMAO @ your life
"""
print(node.refs)
def populate(node):
"""
Populate our node with some data
"""
for i in range(1,random.randint(2,10)):
new_tmp = new_node(random.randint(0,100))
node.refs.append(new_tmp)
def child_count(node):
print(f'{len(node.refs)}')
if __name__ == "__main__":
root = Node(0)
for i in 'ABCDE':
add_node(root, i)
print(f'Children count of root: {len(root.refs)}')
for i in root.refs:
populate(i)
child_count(i)
print('Root node:')
show_children(root)

37
370/samples/tree.py Normal file
View File

@@ -0,0 +1,37 @@
#!/usr/bin/python3
import random # just for some basic population methods
class Node:
def __init__(self,data):
self.data = data
self.children = []
def __str__(self):
return self.data
def __repr__(self):
return f'{self.__str()}:{self.children}'
def new_node(data):
return Node(data)
def add_node(node, lr, val):
node.children.append()
return None
def lvr(root):
"""
Inorder traversal
"""
# left sequence
if root.left is not None:
lvr(root.left)
# visit sequence
print(root.data)
# right sequence
if root.right is not None:
lvr(root.right)
return

32
370/samples/trie.py Normal file
View File

@@ -0,0 +1,32 @@
# Syntax tree in disguise
class Node:
def __init__(self, symbol=None, leaf=False, children={}):
# root node doesn't need any actual data
self.symbol = None
self.leaf = leaf
# {key=char : value=Node}
self.children = children
class Trie:
def __init__(self):
# root should contain every letter so that we can pick our thing
root = Node()
#wrapper func
def traverse(self, func, phrase, _node):
# wew lad
def func(_phrase, _node):
return func(phrase)
@traverse
def insert(self, phrase, node):
pass
@traverse
def remove(self, phrase, node):
pass
@traverse
def checkPhrase(self, phrase):
pass