I'm new in Go and writing a simple insertion sort but when i change my fileName to "insertion.go" I got error:
invalid identifier character U+00A0 at insertion.go:2:1
but when I change the filename to anything else it works fine:
insertion.go
package main
import (
"fmt"
"math/rand"
"time"
)
func main() {
slice := generateSlice(20)
fmt.Println("
--- Unsorted ---
", slice)
insertionsort(slice)
fmt.Println("
--- Sorted ---
", slice, "
")
}
func generateSlice(size int) []int {
slice := make([]int, size, size)
rand.Seed(time.Now().UnixNano())
for i := 0; i < size; i++ {
slice[i] = rand.Intn(999) - rand.Intn(999)
}
return slice
}
func insertionsort(items []int) {
var n = len(items)
for i := 1; i < n; i++ {
j := i
for j > 0 {
if items[j-1] > items[j] {
items[j-1], items[j] = items[j], items[j-1]
}
j = j - 1
}
}
}
I want to know what's the problem with name "insertion"?