Giter Site home page Giter Site logo

lanicon / binarytree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from marusyk/binarytree

0.0 1.0 0.0 105 KB

Cross platform Binary Tree C# implementation as NuGet package

License: MIT License

C# 69.19% Batchfile 0.81% PowerShell 21.81% Shell 8.19%

binarytree's Introduction

HttpPatch

BinaryTree

C# Binary tree

This little project contains a cross platform Binary Tree implementation

Windows Build MacOs Build Linux Build

AppVeyor GitHub release NuGet package NuGet License contributions welcome

How to Install

You can directly install this library from Nuget. There is package:

BinaryTree

PM> Install-Package BinaryTree

How to use

Create a new instanse: var binaryTree = new BinaryTree<int>(); and add elements:

binaryTree.Add(8);
binaryTree.Add(5);
binaryTree.Add(12)

or use collection initializer like : var binaryTree = new BinaryTree<int>() { 8, 5, 12, 3, 7, 10, 15 };

Another way is constructs a BinaryTree, copying the contents of the given collection

IList<int> numbers = new List<int>();
var binaryTree = new BinaryTree<int>(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<int>(10);

By default traversal is set to In-order
You can set the type of traversal in constructor var binaryTree = new BinaryTree<int>(new PostOrderTraversal<int>()); or use property TraversalStrategy:

var inOrder = new InOrderTraversal<int>();
var preOrder = new PreOrderTraversal<int>();
var postOrder = new PostOrderTraversal<int>();

binaryTree.TraversalStrategy = preOrder;

Available operations:

  • void Add(T value) - adds a new element to the tree
  • void AddRange(IEnumerable<T> collection) - copying the contents of the given collection to the tree
  • ITraversalStrategy<T> 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<T> GetEnumerator() - returns numerator of tree

To display all elements of tree, use:

foreach (var item in binaryTree)
{
   Console.Write(item + " ");
}

or use extension method:

binaryTree.PrintToConsole();

Contributing

Please read 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 file for details

binarytree's People

Contributors

marusyk avatar afucher avatar divakar-kumar avatar muhihsan avatar programm3r avatar pszczolas avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.