Giter Club home page Giter Club logo

go-binary-search-tree's Introduction

Binary search trees in Go

Simple implementations of a binary search tree written in GoLang. For more information: basic

Her

Installation

$>go get github.com/m2omou/go-binary-search-tree
import "github.com/m2omou/go-binary-search-tree"

Methods

insert(item)

Inserts the item into the tree. Returns true if inserted, false if duplicate.

remove(item)

Removes the item from the tree. Returns true if removed, false if not found.

size()

Number of nodes in the tree.

Exists()

Returns true if the key exists or return false.

showInOrder()

Print the tree in-order.

showPreOrder()

Print the tree pre-order.

showPostOrder()

Print the tree post-order.

Usage

  // Creating a binary search tree
	test := NewBst()

	// Inserting some data
	test.Insert(4)
	test.Insert(1)
	test.Insert(22)
	test.Insert(699)
	test.Insert(88)

	// Number of nodes in the tree
	fmt.Println(test.Size())

	// Removes the item from the tree. 
	// Returns true if removed, false if not found.
	test.Delete(4)

	// Returns true if the key exists or return false
	fmt.Println(test.Exists(4))
	fmt.Println(test.Exists(1))

Tree traversal

	// Print the tree in-order
	// Traverse the left sub-tree, root, right sub-tree
	showInOrder(test.root)

	// Print the tree pre-order
	// Traverse the root, left sub-tree, right sub-tree
	showPreOrder(test.root)

	// Print the tree post-order
	// Traverse left sub-tree, right sub-tree, root
	showPostOrder(test.root)

Her

go-binary-search-tree's People

Contributors

arush-sal avatar m2omou avatar

Watchers

 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.