Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Golang version #2

Merged
merged 7 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center" id="top">
<img src="./.github/app.gif" alt="Binarysearchtree" />

&#xa0;
&#xa0;

<!-- <a href="https://binarysearchtree.netlify.app">Demo</a> -->
</div>
Expand All @@ -26,9 +26,9 @@

<!-- Status -->

<!-- <h4 align="center">
<!-- <h4 align="center">
🚧 Binarysearchtree 🚀 Under construction... 🚧
</h4>
</h4>

<hr> -->

Expand All @@ -44,29 +44,30 @@

<br>

## :dart: About ##
## :dart: About

Repository used to study and implement the binary tree search algorithm
Repository used to study and implement the binary tree search algorithm

## :sparkles: Features ##
## :sparkles: Features

:heavy_check_mark: insert
:heavy_check_mark: Asc Order
:heavy_check_mark: Dec Order

## :rocket: Technologies ##
## :rocket: Technologies

The following tools were used in this project:

- [Node.js](https://nodejs.org/en/)
- [JavaScript](https://developer.mozilla.org/pt-BR/docs/Web/JavaScript)
- [TypeScript](https://www.typescriptlang.org/)
- [GoLang](https://go.dev/doc/)

## :white_check_mark: Requirements ##
## :white_check_mark: Requirements

Before starting :checkered_flag:, you need to have [Git](https://git-scm.com) and [Node](https://nodejs.org/en/) installed.

## :checkered_flag: Starting ##
## :checkered_flag: Starting

```bash
# Clone this project
Expand All @@ -76,19 +77,22 @@ $ git clone https://github.com/apenasgabs/binarysearchtree
$ cd binarysearchtree

# Install dependencies
$ yarn
$ npm i

# Run the project
$ yarn start
$ npm run js

$ npm run ts

$ npm run go

# The server will initialize in the <http://localhost:3000>
```

## :memo: License ##
## :memo: License

This project is under license from MIT. For more details, see the [LICENSE](LICENSE.md) file.


Made with :heart: by <a href="https://github.com/apenasgabs" target="_blank">Gabriel Rodrigues</a>

&#xa0;
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/Apenasgabs/BinarySearchTree

go 1.21.4
4 changes: 0 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@ class Node {
}
}

// const MyNode = new Node('batata')

// console.log('MyNode: ', MyNode);

class BinarySearchTree {
constructor() {
this.root = null;
Expand Down
49 changes: 49 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package main

type Node struct {
Left *Node
Right *Node
Value int
}

func (node *Node) Insert(value int) {
if node == nil {
return
}
if node.Value > value {
if node.Left == nil {
node.Left = &Node{Value: value}
} else {
node.Left.Insert(value)
}
} else {
if node.Right == nil {
node.Right = &Node{Value: value}
} else {
node.Right.Insert(value)
}
}
}

func (node *Node) ascOrder() {
if node == nil {
return
}
if node.Left != nil {
node.Left.ascOrder()
}
println(node.Value)
if node.Right != nil {
node.Right.ascOrder()
}
}
func main() {
root := &Node{Value: 10}
root.Insert(5)
root.Insert(15)
root.Insert(8)
root.Insert(3)
root.Insert(2)
root.Insert(18)
root.ascOrder()
}
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"main": "index.ts",
"scripts": {
"build": "tsc",
"start": "node ./dist/index.js",
"dev": "ts-node src/index.ts"

"js": "node index.js",
"ts": "ts-node src/index.ts",
"go": "go run main.go"
},
"keywords": [],
"author": "ApenasGabs",
Expand Down