func main() { f, _ := os.Open(os.Args[1]) defer f.Close() v := vec.MakeVector(0, 0) for { var i int n, _ := fmt.Fscanf(f, "%d,", &i) if n == 0 { n, _ = fmt.Fscanf(f, "%d", &i) if n == 0 { break } } // fmt.Printf("Got: %d\n", i) v.Push_back(i) } sorter.MSort(&v) last := -1 for v := range v.Items() { if last > v { fmt.Printf("%d > %d ???\n", last, v) } last = v fmt.Printf("%d\n", v) } }
func mhelp(v *vec.Vector, b, e int, c chan int) { if debug { fmt.Printf("mhelp(%d, %d)\n", b, e) } if (e - b) < 1 { c <- 1 return } c1 := make(chan int) c2 := make(chan int) mid := (e-b)/2 + b go mhelp(v, b, mid, c1) go mhelp(v, mid+1, e, c2) <-c1 <-c2 i := b j := mid + 1 l := e - b + 1 sorted := vec.MakeVector(l, 0) p := 0 for i <= mid && j <= e { var m int if *v.At(i) < *v.At(j) { m = *v.At(i) i++ } else { m = *v.At(j) j++ } *sorted.At(p) = m p++ } for i <= mid { *sorted.At(p) = *v.At(i) i++ p++ } for j <= e { *sorted.At(p) = *v.At(j) j++ p++ } for ix := 0; ix < l; ix++ { *v.At(b + ix) = *sorted.At(ix) } c <- 1 }