-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpush-swap.go
executable file
·50 lines (48 loc) · 920 Bytes
/
push-swap.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"fmt"
"os"
pushswap "pushswap/algo"
"pushswap/utils"
"sort"
)
func main() {
var (
nums []int
err error
)
if utils.FlagRandPassed() {
nums, err = utils.GenerateRandomInts()
if err != nil {
fmt.Println("Error")
return
}
} else {
args := os.Args[1:]
if len(args) < 1 {
return
}
nums, err = utils.UniqInts(args[0])
if err != nil {
fmt.Println("Error")
return
}
}
if sort.IntsAreSorted(nums) {
return
}
file, _ := os.Create("push-swap-result.txt")
defer file.Close()
numsToStr := fmt.Sprint(nums)
file.WriteString("\"" + numsToStr[1:len(numsToStr)-1] + "\"\n")
instructions := ""
utils.UInts(nums)
if len(nums) <= 100 {
instructions = pushswap.SmallSort(nums)
} else {
instructions = pushswap.RadixSort(nums)
}
fmt.Print(instructions)
file.WriteString(instructions)
//fmt.Println("step ", len(strings.Split(instructions, "\n"))-1)
}