Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/marusyk/binarytree
Binary Tree as a cross platform NuGet package
https://github.com/marusyk/binarytree
algorithm binary-trees binarytree c-sharp-library csharp dotnet dotnet-standard hacktoberfest nuget nuget-package tree
Last synced: 8 days ago
JSON representation
Binary Tree as a cross platform NuGet package
- Host: GitHub
- URL: https://github.com/marusyk/binarytree
- Owner: Marusyk
- License: mit
- Created: 2016-05-25T23:16:16.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2024-10-18T12:18:30.000Z (27 days ago)
- Last Synced: 2024-10-31T09:41:56.874Z (15 days ago)
- Topics: algorithm, binary-trees, binarytree, c-sharp-library, csharp, dotnet, dotnet-standard, hacktoberfest, nuget, nuget-package, tree
- Language: C#
- Homepage:
- Size: 127 KB
- Stars: 31
- Watchers: 5
- Forks: 20
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
# BinaryTree [![Stand With Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://stand-with-ukraine.pp.ua)
C# Binary tree
This project contains a cross platform Binary Tree implementation
[![Build](https://github.com/Marusyk/BinaryTree/actions/workflows/builds.yml/badge.svg)](https://github.com/Marusyk/BinaryTree/actions/workflows/builds.yml)
[![AppVeyor](https://ci.appveyor.com/api/projects/status/l3kmfu18f4fbmuvu?svg=true)](https://ci.appveyor.com/project/Marusyk/binarytree)
[![GitHub release](https://badge.fury.io/gh/Marusyk%2FBinaryTree.svg)](https://github.com/Marusyk/BinaryTree/releases/tag/v5.2.0)
[![NuGet package](https://badge.fury.io/nu/BinaryTree.svg)](https://www.nuget.org/packages/BinaryTree/)
[![NuGet](https://img.shields.io/nuget/dt/BinaryTree.svg)](https://www.nuget.org/packages/BinaryTree/)
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/Marusyk/BinaryTree/blob/main/LICENSE)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/Marusyk/BinaryTree/blob/main/CONTRIBUTING.md)# Code Coverage
[![Coverage Status](https://coveralls.io/repos/github/Marusyk/BinaryTree/badge.svg?branch=main)](https://coveralls.io/github/Marusyk/BinaryTree?branch=main)
# How to Install
You can directly install this library from [Nuget](http://nuget.org). There is package:
**[BinaryTree](https://www.nuget.org/packages/BinaryTree)**
PM> Install-Package BinaryTree
# How to use
Create a new instanse:
`var binaryTree = new BinaryTree();`
and add elements:``` csharp
binaryTree.Add(8);
binaryTree.Add(5);
binaryTree.Add(12)
```or use collection initializer like : `var binaryTree = new BinaryTree() { 8, 5, 12, 3, 7, 10, 15 };`
Another way is constructs a BinaryTree, copying the contents of the given collection
```csharp
IList numbers = new List();
var binaryTree = new BinaryTree(numbers);
```Also you can initialize a new instance of the BinaryTree class that is empty and has the specified initial capacity:
`var binaryTree = new BinaryTree(10);`By default traversal is set to [**In-order**](https://en.wikipedia.org/wiki/Tree_traversal#In-order)
You can set the type of traversal in constructor `var binaryTree = new BinaryTree(new PostOrderTraversal());`
or use property `TraversalStrategy`:```csharp
var inOrder = new InOrderTraversal();
var preOrder = new PreOrderTraversal();
var postOrder = new PostOrderTraversal();binaryTree.TraversalStrategy = preOrder;
```Available operations:
- `void Add(T value)` - adds a new element to the tree
- `void AddRange(IEnumerable collection)` - copying the contents of the given collection to the tree
- `ITraversalStrategy TraversalStrategy` -gets or sets type of traversal(Pre-order, In-order, Post-order)
- `int Count` - returns count of elements in tree
- `int Capacity` - gets the number of elements that the BinaryTree can contain
- `bool IsReadOnly` - always return `false`
- `bool IsFixedSize` - gets a value indicating whether the BinaryTree has a fixed size
- `bool Contains(T value)` - checks if the tree contains the element
- `bool Remove(T value)` - remove element from the tree. Returns `true` if element was removed.
- `void Clear()` - clears tree
- `void CopyTo(T[] array, int arrayIndex)` - copies all the elements of the tree to the specified one-dimensional array starting at the specified destination array index.
- `IEnumerator GetEnumerator()` - returns numerator of treeTo display all elements of tree, use:
```csharp
foreach (var item in binaryTree)
{
Console.Write(item + " ");
}
```or use extension method:
```csharp
binaryTree.PrintToConsole();
```## Operations complexity
Time Complexity
Space Complexity
Avarage
Worst
Worst
Access
Search
Insertion
Deletion
Access
Search
Insertion
Deletion
O(log(n))
O(log(n))
O(log(n))
O(log(n))
O(n)
O(n)
O(n)
O(n)
O(n)
## Build
On Windows:
```powershel
build.ps1
```On Linux/Mac:
```bash
build.sh
```## Contributing
Please read [CONTRIBUTING.md](https://github.com/Marusyk/BinaryTree/blob/main/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
## License
This project is licensed under the MIT License - see the [LICENSE.md](https://github.com/Marusyk/BinaryTree/blob/main/LICENSE) file for details