func main() { flag.Parse() if infile != nil { fmt.Println("infile = ", *infile, "outfile = ", *outfile, "algorithm = ", *algorithm) } values, err := readValues(*infile) if err == nil { fmt.Println("read values", values) t1 := time.Now() switch *algorithm { case "bubblesort": bubblesort.Bubblesort(values) } t2 := time.Now() fmt.Println("sorting cost ", t2.Sub(t1)) err1 := writeValues(values, outfile) if err1 != nil { fmt.Println("Failed to write values to file ", *outfile) } fmt.Println("write values successfully") } else { fmt.Println(err) } }
func main() { flag.Parse() if infile != nil { fmt.Println("infile =", *infile, "outfile =", *outfile, "algorithm =", *algorithm) } values, err := readValues(*infile) if err == nil { t1 := time.Now() switch *algorithm { case "qsort": qsort.Qsort(values) case "bubblesort": bubblesort.Bubblesort(values) default: fmt.Println("Sorting algorithm", *algorithm, "is either unknown or unsupported") } t2 := time.Now() fmt.Println("The sorting process costs", t2.Sub(t1), "to complete") writeValues(values, *outfile) } else { fmt.Println(err) } }