Skip to main content

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

Metadata

Release files for treestructure 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for treestructure 1.1.0
File Size Uploaded
treestructure-1.1.0.tar.gz 13.7 kB Details

Release files / treestructure-1.1.0.tar.gz

Download URL treestructure-1.1.0.tar.gz
Size 13.7 kB
Tags Source
SHA-256 checksum
How to use checksums
ab5b7b48efaf7bc320cd66c9f9cb3ef8528a59fab8820267b50ed751f6532142
BLAKE2b-256 checksum
How to use checksums
9c54fef8c2bb4d31f3a9fe081e2eba10011917c5477833559276e0b49686613e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.5

Release history Release notifications | RSS feed

This release

1.1.0 This release

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page