prawn-cake / data_structures Goto Github PK
View Code? Open in Web Editor NEWPure python data structures implementations
License: MIT License
Pure python data structures implementations
License: MIT License
@classmethod
def pre_order_traversal(cls, node):
order = []
stack = [node]
while stack:
current_node = stack.pop()
order.append(current_node.value)
if current_node.right:
stack.append(current_node.right)
# Put left always on top of stack
if current_node.left:
stack.append(current_node.left)
return order
...
@classmethod
def level_order_traversal(cls, node):
"""Level order traversal is implemented with queue
Steps:
1. Add node value to order list and go ahead
2. Put next node to the queue (left AND/OR right if exists)
3. Declare while loop and repeat first two steps until the length
is 0
"""
order = []
queue = deque([node])
while len(queue) != 0:
current_node = queue.pop()
order.append(current_node.value)
if current_node.left:
queue.appendleft(current_node.left)
if node.right:
queue.appendleft(current_node.right)
return order
@classmethod
def in_order_traversal(cls, node):
order = []
stack = []
current_node = node
while stack or current_node is not None:
# go down till the last left child
if current_node is not None:
stack.append(current_node)
current_node = current_node.left
else:
# once we reach last left child start to visit closest right child
current_node = stack.pop()
order.append(current_node)
current_node = current_node.right
return order
...
etc
To extend the collection of data structures
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.