I am implementing sorting but keep getting the index bound error in Go language.
My code is following
func My_Partition(container []int, first_index int, last_index int) int {
var x int = container[last_index]
i := first_index - 1
for j := first_index; i < last_index; j++ {
if container[j] <= x {
i += 1
my_Swap(&container[i], &container[j])
}
}
my_Swap(&container[i+1], &container[last_index])
return i+1
}
I am getting error in the line "if container[j] <= x" that says panic: runtime error: index out of range
main.My_Partition(0x2101b20c0, 0x7, 0x7, 0x0, 0x6, ...)
/Path/main.go:34 +0xff
Anybody has an idea?
my swap function is below
func my_Swap(a *int, b *int) {
temp := *a
*a = *b
*b = temp
}
but I don't think swap is the problem.