pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/BaseMax/TreeTraversalsGo

media="all" rel="stylesheet" href="https://github.githubassets.com/assets/primer-71a44d5be3f782c5.css" /> GitHub - BaseMax/TreeTraversalsGo: This is a simple Go program that traverses a tree in different ways. (Pre-order, In-order, Post-order, and Level-order)
Skip to content

This is a simple Go program that traverses a tree in different ways. (Pre-order, In-order, Post-order, and Level-order)

License

Notifications You must be signed in to change notification settings

BaseMax/TreeTraversalsGo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tree-Traversals Go

This is a simple Go program that traverses a tree in different ways. (Pre-order, In-order, Post-order, and Level-order)

Methods

  • Pre-order
  • In-order
  • Post-order
  • Level-order
  • Reverse level-order

Output

InOrder:

8, 4, 9, 2, 10, 5, 11, 1, 3, 12, 7, 13

PreOrder:

1, 2, 4, 8, 9, 5, 10, 11, 3, 7, 12, 13

PostOrder:

8, 9, 4, 10, 11, 5, 2, 12, 13, 7, 3, 1

LevelOrder:

1, 2, 4, 8, 9, 5, 10, 11, 3, 7, 12, 13

ReverseLevelOrder:

13, 12, 7, 3, 11, 10, 5, 9, 8, 4, 2, 1

Usage

// Create a large general-tree
tree := BinaryTree{
    Root: &Node{
        Value: 1,
        Left: &Node{
            Value: 2,
            Left: &Node{
                Value: 4,
                Left: &Node{
                    Value: 8,
                },
                Right: &Node{
                    Value: 9,
                },
            },
            Right: &Node{
                Value: 5,
                Left: &Node{
                    Value: 10,
                },
                Right: &Node{
                    Value: 11,
                },
            },
        },
        Right: &Node{
            Value: 3,
            Right: &Node{
                Value: 7,
                Left: &Node{
                    Value: 12,
                },
                Right: &Node{
                    Value: 13,
                },
            },
        },
    },
}

// Print the tree
fmt.Println("Tree:")
// tree.Print()
fmt.Println(tree.String())

// Print the tree in pre-order
fmt.Println("PreOrder:")
// tree.PreOrder()
fmt.Println(tree.StringPreOrder())

// Print the tree in in-order
fmt.Println("InOrder:")
// tree.InOrder()
fmt.Println(tree.StringInOrder())

// Print the tree in post-order
fmt.Println("PostOrder:")
// tree.PostOrder()
fmt.Println(tree.StringPostOrder())

// Print the tree in level-order
fmt.Println("LevelOrder:")
// tree.LevelOrder()
fmt.Println(tree.StringLevelOrder())

// Print the tree in reverse-level-order
fmt.Println("ReverseLevelOrder:")
// tree.ReverseLevelOrder()
fmt.Println(tree.StringReverseLevelOrder())

License

This project is licensed under the GPL-3.0 License - see the LICENSE.md file for details.

Copyright (c) 2022, Max Base

About

This is a simple Go program that traverses a tree in different ways. (Pre-order, In-order, Post-order, and Level-order)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy