Giter Site home page Giter Site logo

sebastian-schuchmann / binary-search-tree Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 1.0 6 KB

A Binary Search Tree in C# with Traversal, Insert, Search and Delete.

C# 100.00%
binary-search-tree binary-search binary-trees binarysearchtree csharp c-sharp data-structures search

binary-search-tree's Introduction

Binary-Search-Tree

Binary Search Trees in general

A binary search trees (BST) is a container that allows fast lookup, addition and removal of items, and can be used to implement either dynamic sets of items, or lookup tables that allow finding an item by its key (e.g., finding the phone number of a person by name).

Binary Search Tree

Binary search trees keep their items in sorted order, so that lookup and other operations can use the principle of binary search: when looking for a item in a tree (or a place to insert a new item), they traverse the tree from root to leaf, making comparisons to item stored in the nodes of the tree and deciding, on the basis of the comparison, to continue searching in the left or right subtrees.

About

This Project implements a Binary Search Tree in C# and has functions for Traversal, Insertion, Deletion and Search.

Example

static void Main(string[] args)
{
    //Building a Tree
    var Tree = new BinarySearchTree<int>();

    //Insert a Value
    Tree.Insert(3);

    //Insert Values
    int[] Values = { 10, 5, 20, 6, 8, 15, 40, 1, 2, 9, 6 };
    Tree.Insert(Values);

    //Print Values (Sorted / InOrder)
    Tree.Traverse((Node<int> node) => Console.Write(node.Value + ", "), TraversalType.InOrder);
    Console.WriteLine();

    //Print Values in reverse sorted Order
    Tree.Traverse((Node<int> node) => Console.Write(node.Value + ", "), TraversalType.OutOrder);
    Console.WriteLine();

    //You can do any operation you want in Tree.Traverse() but, be warned...
    //... you can change the values and this can mess up the Tree!

    //Find a Node with a Value
    var Node = Tree.Search(8);

    //Delete a Node
    Tree.DeleteNode(Node);
}

binary-search-tree's People

Contributors

sebastian-schuchmann avatar sscdemodern avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

srinathck

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.