Last active
January 16, 2023 12:17
-
-
Save zdunecki/8f89bb4709fecfdc5d3aad8ebf8d2d38 to your computer and use it in GitHub Desktop.
First Sort data structure
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func push(arr *[]int, elements... int) { | |
for i, v := range elements { | |
fmt.Println(i) | |
if len(*arr) <= 0 { | |
*arr = append(*arr, v) | |
} else { | |
a := *arr | |
f := a[0] | |
if v > f { | |
a := *arr | |
a[0] = v | |
*arr = append(*arr, f) | |
} else { | |
*arr = append(*arr, v) | |
} | |
} | |
} | |
} | |
func main() { | |
a := make([]int, 0) | |
push(&a, 1, 5, 10, 2, 33, 0, 0, 2, 10, 150, 2, 4, 1 ,53, 63) | |
fmt.Println("-----") | |
push(&a, 5, 150, 400, 2, 3, 4) | |
fmt.Println("-----") | |
push(&a, 500) | |
fmt.Println(a) | |
} | |
``` | |
go build | |
./main | |
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
6 | |
7 | |
8 | |
9 | |
10 | |
11 | |
12 | |
13 | |
14 | |
----- | |
0 | |
1 | |
2 | |
3 | |
4 | |
5 | |
----- | |
0 | |
[500 1 5 2 10 0 0 2 10 33 2 4 1 53 63 5 150 150 2 3 4 400] | |
``` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment