GithubHelp home page GithubHelp logo

minmaxheap's Introduction

Binary Heap

A Binary Heap is either Min Heap or Max Heap. In a Min Binary Heap, the key at root must be minimum among all keys present in Binary Heap. The same property must be recursively true for all nodes in Binary Tree. Max Binary Heap is similar to MinHeap, except the root must be maximum among all keys present.

Documentation

Click here to explore the documentation

Example

The following piece of code uses the library for min heap

// Create an instance of the Heap
let mut min = Heap::new("min", 6).expect("Something did not work");

// Add value into the binary tree in no particular order
min.add(20);
min.add(10);
min.add(5);
min.add(100);
min.add(2);
min.add(40);

// Print out the results
println!("{}", min);

The result output is

Number of nodes: 6
---------------------------------------
Node: 2 Left: 5 Right: 10
---------------------------------------
Node: 5 Left: 100 Right: 20
---------------------------------------
Node: 10 Left: 40

The following piece of code uses the library for max heap

// Create an instance of the Heap
let mut test = Heap::new("max", 6).expect("Something did not work");

// Add value into the binary tree in no particular order
test.add(20);
test.add(10);
test.add(5);
test.add(100);
test.add(2);
test.add(40);

// Print out the results
println!("{}", test);

The result output is

Number of nodes: 6
---------------------------------------
Node: 100 Left: 20 Right: 40
---------------------------------------
Node: 20 Left: 10 Right: 2
---------------------------------------
Node: 40 Left: 5

minmaxheap's People

Contributors

cosmicsyntax 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.