Commit 62b0029f authored by richardARPANET's avatar richardARPANET

Initial commit

parents
#pycharm .idea .cache ################# ## Eclipse ################# *.pydevproject .project .metadata bin/ tmp/ .vscode *.tmp *.bak *.swp *~.nib local.properties .classpath .settings/ .loadpath .idea htmlcov/ # External tool builders .externalToolBuilders/ # Locally stored "Eclipse launch configurations" *.launch # CDT-specific .cproject # PDT-specific .buildpath ################# ## Visual Studio ################# ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. # User-specific files *.suo *.user *.sln.docstates # Build results [Dd]ebug/ [Rr]elease/ *_i.c *_p.c *.ilk *.meta *.obj *.pch *.pdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.vspscc .builds *.dotCover ## TODO: If you have NuGet Package Restore enabled, uncomment this #packages/ # Visual C++ cache files ipch/ *.aps *.ncb *.opensdf *.sdf # Visual Studio profiler *.psess *.vsp # ReSharper is a .NET coding add-in _ReSharper* # Installshield output folder [Ee]xpress # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish # Others [Bb]in [Oo]bj sql TestResults *.Cache ClientBin stylecop.* ~$* *.dbmdl Generated_Code #added for RIA/Silverlight projects # Backup & report files from converting an old project file to a newer # Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML ############ ## Windows ############ # Windows image file caches Thumbs.db # Folder config file Desktop.ini ############# ## Python ############# *.py[co] # Packages *.egg *.egg-info dist build eggs parts bin var sdist develop-eggs .installed.cfg # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox # virtual env venv #Translations *.mo #Mr Developer .mr.developer.cfg # Mac crap .DS_Store *.sqlite
#pycharm
.idea
.cache
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
.vscode
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
.idea
htmlcov/
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.vspscc
.builds
*.dotCover
## TODO: If you have NuGet Package Restore enabled, uncomment this
#packages/
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
# Visual Studio profiler
*.psess
*.vsp
# ReSharper is a .NET coding add-in
_ReSharper*
# Installshield output folder
[Ee]xpress
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish
# Others
[Bb]in
[Oo]bj
sql
TestResults
*.Cache
ClientBin
stylecop.*
~$*
*.dbmdl
Generated_Code #added for RIA/Silverlight projects
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
############
## Windows
############
# Windows image file caches
Thumbs.db
# Folder config file
Desktop.ini
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist
build
eggs
parts
bin
var
sdist
develop-eggs
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
# virtual env
venv
#Translations
*.mo
#Mr Developer
.mr.developer.cfg
# Mac crap
.DS_Store
*.sqlite
import json
class BinaryTree:
def __init__(self, *, data, left=None, right=None):
self.data = data
self.left = left
self.right = right
self.depth = 0
self._set_depth(self.depth)
def _set_depth(self, depth):
if self.left is not None:
self.left._set_depth(depth+1)
if self.right is not None:
self.right._set_depth(depth+1)
self.depth = depth
def create_repr(self):
output = {}
next_item = {'left': None, 'right': None}
if self.left is not None:
next_item['left'] = self.left.create_repr()
if self.right is not None:
next_item['right'] = self.right.create_repr()
output.update({self.data: next_item})
return output
def reverse(self):
self.right, self.left = self.left, self.right
if self.left is not None:
self.left.reverse()
if self.right is not None:
self.right.reverse()
def print_tree(self):
print(json.dumps(self.create_repr(), indent=4, sort_keys=True))
print('Creating binary tree')
tree = BinaryTree(
data='level 1 data',
left=BinaryTree(
data='level 2 data left', right=BinaryTree(data='level 3 data')
),
right=BinaryTree(data='level 2 data right'),
)
tree.print_tree()
print('Reversing...')
tree.reverse()
tree.print_tree()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment