Skip to main content

Tree Structure is a module that implements some common trees in data structure.

Project description

Tree Structure

Pypi link

Tree Structure is a module that implements some common trees in data structure.

Quick Start

There are two basic components in each type of tree structure: Node and Tree.
Each node has two basic attributes: order and value.
Order is the key to construct the tree structure. Default order is current timestamp.
Value can be anything you want to store. Default value is None.

>>> import treestructure
>>> node = treestructure.BinaryNode(35, 'Stevie Wonder') # Create node
>>> node.order
35
>>> node.value
'Stevie Wonder'

Insert node into tree to build the tree structure.
Use package() to check the tree structure. It's better using package() with pprint module.

>>> import pprint
>>> tree = treestructure.BinarySearchTree(node) # Create tree
>>> tree.insertNode(treestructure.BinaryNode(45, 'Ray Charles')) # Insert node
>>> tree.insertNode(treestructure.BinaryNode(25, 'Lionel Richie')) # Insert node
>>> pprint.pprint(tree.package(), sort_dicts=False) # Display tree
{'order': 35,
 'value': 'Stevie Wonder',
 'leftChildNode': {'order': 25,
                   'value': 'Lionel Richie',
                   'leftChildNode': None,
                   'rightChildNode': None},
 'rightChildNode': {'order': 45,
                    'value': 'Ray Charles',
                    'leftChildNode': None,
                    'rightChildNode': None}}

Delete node by specific order.

>>> delNode = tree.deleteNode(35) # Delete node
>>> pprint.pprint(delNode.package(), sort_dicts=False) # Display node
{'order': 35,
 'value': 'Stevie Wonder',
 'leftChildNode': {},
 'rightChildNode': {},
 'parentNode': {}}
>>> pprint.pprint(tree.package(), sort_dicts=False) # Display tree
{'order': 25,
 'value': 'Lionel Richie',
 'leftChildNode': None,
 'rightChildNode': {'order': 45,
                    'value': 'Ray Charles',
                    'leftChildNode': None,
                    'rightChildNode': None}}

Contents

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

treestructure-1.1.0.tar.gz (13.7 kB view details)

Uploaded Source

File details

Details for the file treestructure-1.1.0.tar.gz.

File metadata

  • Download URL: treestructure-1.1.0.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.5

File hashes

Hashes for treestructure-1.1.0.tar.gz
Algorithm Hash digest
SHA256 ab5b7b48efaf7bc320cd66c9f9cb3ef8528a59fab8820267b50ed751f6532142
MD5 755c04ed6d1f5fb36ba51449b9104e09
BLAKE2b-256 9c54fef8c2bb4d31f3a9fe081e2eba10011917c5477833559276e0b49686613e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page