Giter VIP home page Giter VIP logo

basemax / completetreelinkedlistgo Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 744 KB

This is a Go program for creating a complete tree using linked list. You can easily insert nodes to the tree and print it. This library provide two inserting functions. One of them is for inserting nodes to the tree by filling the tree from left to right in per row. and the next one is to insert to left side of the tree.

License: GNU General Public License v3.0

Go 100.00%
complete-tree data-structure go golang linked-list linkedlist tree tree-complete tree-search tree-structure

completetreelinkedlistgo's Introduction

Complete Tree Linked List (Go)

This is a Go program for creating a complete tree using linked list. You can easily insert nodes to the tree and print it. This library provide two inserting functions. One of them is for inserting nodes to the tree by filling the tree from left to right in per row. The other one is for inserting nodes to the tree by filling the tree to the left side of the tree.

Using

In the following we will create an empty Complete Tree and add some values to it.

Finally we will print the heap tree.

// create a new heap tree
heapTree := NewHeapTree()

// insert some values
heapTree.Insert(1)
heapTree.Insert(2)
heapTree.Insert(3)
heapTree.Insert(4)
heapTree.Insert(5)
heapTree.Insert(6)
heapTree.Insert(7)
heapTree.Insert(8)
heapTree.Insert(9)
heapTree.Insert(10)

// print heap tree
heapTree.Print()

The output of above code will be:

    3
1
        5
    2
            7
        4
                9
            6
                8
                    10

Also, there are another inserting function that it will insert the value to left and the right of node by filling the tree from left to right in per row.

// Create another complete tree
CompleteTree2 := NewCompleteTree()

// Insert some values
CompleteTree2.InsertClean(10)
CompleteTree2.InsertClean(9)
CompleteTree2.InsertClean(8)
CompleteTree2.InsertClean(7)
CompleteTree2.InsertClean(6)
CompleteTree2.InsertClean(5)
CompleteTree2.InsertClean(4)
CompleteTree2.InsertClean(3)
CompleteTree2.InsertClean(2)
CompleteTree2.InsertClean(1)

// Print the tree
CompleteTree2.Print()

And the output will be:

                2
                    1
            4
                3
                    1
        6
                2
                    1
            5
                3
                    1
    8
                2
                    1
            4
                3
                    1
        7
                2
                    1
            5
                3
                    1
10
                2
                    1
            4
                3
                    1
        6
                2
                    1
            5
                3
                    1
    9
                2
                    1
            4
                3
                    1
        7
                2
                    1
            5
                3
                    1

Copyright (c) 2022, Max Base

completetreelinkedlistgo's People

Stargazers

 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.